[HELP] Making a Save button

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: [HELP] Making a Save button

Post by nice »

DaedalusYoung wrote:No, love.mousepressed is a callback function. LÖVE calls it automatically when the mouse is pressed, it is your job to write the function.

If you wanted to do it the way you described, you could do it with [utl=http://www.love2d.org/wiki/love.mouse.isDown]love.mouse.isDown[/url], but that would trigger every frame, as long as you keep the mouse pressed. You'd need to add additional checks for this, and it isn't really intended to be used like this.
So would it be better if I separate them instead? one that saves and one that opens the containing folder? will that be better for a smoother experience?

[EDIT]
The love.mousepressed explanation were just an example and it's as you say, I don't want to trigger it every frame, I just want it to trigger once.
:awesome: Have a good day! :ultraglee:
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [HELP] Making a Save button

Post by zorg »

Code: Select all

function love.mousepressed(x,y,button)
  -- if mouse is clicked with left button over the save button, trigger saving and open the folder containing the file
  if button == 'l' and x > savebutton.x and x <= savebutton.x+savebutton.w and y > savebutton.y and y <= savebutton.x+savebutton.w then
    saveImage() -- excercise for the reader
    openFolder()  -- same as above
  end
end
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: [HELP] Making a Save button

Post by undef »

zorg wrote:

Code: Select all

function love.mousepressed(x,y,button)
  -- if mouse is clicked with left button over the save button, trigger saving and open the folder containing the file
  if button == 'l' and x > savebutton.x and x <= savebutton.x+savebutton.w and y > savebutton.y and y <= savebutton.x+savebutton.w then
    saveImage() -- excercise for the reader
    openFolder()  -- same as above
  end
end
Now he doesn't get to figure it out himself :(
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [HELP] Making a Save button

Post by zorg »

undef wrote:Now he doesn't get to figure it out himself :(
Sure he does, who knows how he defined a button, maybe he needs to adapt it! :3
(i want to believe i didnt spoil ALL the fun)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: [HELP] Making a Save button

Post by nice »

undef wrote:Now he doesn't get to figure it out himself :(
I understand your concern is just that I like to see examples and hear other peoples insight and trying to find out the best solution for a saving function.
zorg wrote: Sure he does, who knows how he defined a button, maybe he needs to adapt it! :3
(i want to believe i didnt spoil ALL the fun)
There are many solutions to one problem and yes, giving me everything would be too easy and it's okay to throw someone some clues and let him/her try to figure out the rest.
But also giving the complete code and reading the code will teach you too but sometimes it might not give you as much experience as perhaps needed.
:awesome: Have a good day! :ultraglee:
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: [HELP] Making a Save button

Post by undef »

Well, what's done is done.
But one advice for the future:

The most important part of learning to code, is to fail.
So next time you want to implement something, and you don't know how to do it, just try.
If it doesn't work, then that means there's something you haven't thought of --> You'll have to think harder.
A lot of times it takes hours to find a solution, but once you've found it, you've added another piece of knowledge to your toolset and you will probably not be riddled the next time you encounter a similar problem. (Unless you need to fail again.)

But yeah, just try stuff. It's not sculpting, there is always undo.
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: [HELP] Making a Save button

Post by nice »

undef wrote:Well, what's done is done.
But one advice for the future:

The most important part of learning to code, is to fail.
So next time you want to implement something, and you don't know how to do it, just try.
If it doesn't work, then that means there's something you haven't thought of --> You'll have to think harder.
A lot of times it takes hours to find a solution, but once you've found it, you've added another piece of knowledge to your toolset and you will probably not be riddled the next time you encounter a similar problem. (Unless you need to fail again.)

But yeah, just try stuff. It's not sculpting, there is always undo.
I completely agree with on the part about learn by doing and that you learn more from failure than success.

But it's just that making a function like saving an image is foreign grounds for me and I don't know where I should start looking, I have no problem with drawing stuff on screen or making an object (maybe a little bit) it's just that I want all the necessary information I need before I start making something.
And I'm sometimes a little bit frustrated when it comes to the documentation with Löve too, because there're some things in there that aren't well documented.
Positive07 wrote:love.filesystem.getAppdataDirectory()
love.filesystem.getWorkingDirectory()
love.filesystem.getUserDirectory()
Like these, they're there but what exactly do they do? it might sound obvious to some of you but in this case I don't really understand.
I know what they are because of what it says in the function but what do they do in detail and how do I find those directories?
undef wrote:

Code: Select all

function saveButton()
    saveImage( IMAGENAME )
    openFolder()
end
slime wrote:

Code: Select all

function OpenFolder()
    love.system.openURL("file://"..love.filesystem.getSaveDirectory())
end
When it comes to it, I can come with the conclusion that I'll need to make a custom function (as in naming it) for the save button to work but it's just that at what end should I start with?
:awesome: Have a good day! :ultraglee:
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: [HELP] Making a Save button

Post by undef »

Like these, they're there but what exactly do they do? it might sound obvious to some of you but in this case I don't really understand.
I know what they are because of what it says in the function but what do they do in detail and how do I find those directories?
Well, things are always obvious once you've understood them.
Just play around with the functions a bit, print their output, and it will become clear.

If you really want to know how the LÖVE functions work under the hood, you can look into the source code, but you don't really need to know how they work right now, and I wouldn't recommend to try and read it as a beginner.

When it comes to it, I can come with the conclusion that I'll need to make a custom function (as in naming it) for the save button to work but it's just that at what end should I start with?
That's pretty much what programming is. Writing and connecting functions.
Just write down a function in a way that you think it should look like, and then check if it does want you want.
If it doesn't - describe further.
Make sure to sufficiently describe under what conditions your function should behave in which way.
If you think it does what you want, execute your program.
If there are errors, fix them

It doesn't really matter at what end you start writing, as long as you connect the pieces correctly.
What does matter however, is that you start.
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [HELP] Making a Save button

Post by zorg »

by the way, you can also look at the wiki, where every function is described in detail :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: [HELP] Making a Save button

Post by nice »

undef wrote: That's pretty much what programming is. Writing and connecting functions.
Just write down a function in a way that you think it should look like, and then check if it does want you want.
If it doesn't - describe further.
Make sure to sufficiently describe under what conditions your function should behave in which way.
If you think it does what you want, execute your program.
If there are errors, fix them

It doesn't really matter at what end you start writing, as long as you connect the pieces correctly.
What does matter however, is that you start.
Thanks for the encouragement, it's appreciated :)
:awesome: Have a good day! :ultraglee:
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests