Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
I made a class called Time that has a method that advances the time, but i don't know how to make a button that just does the method instead of having to create a label and then actually call the method to advance time.
I just want to click the button and the method is executed... but unfortunatelly i don't know how, right now i have the line of code like this:
textbutton "Advance time 1 hour" action Time.one_hour_advance()
Time is an instance of my Time class and one_hour_advance() is my method inside that class, this gives me an error when i press the button because clearly im doing something wrong here.
textbutton "Advance time 1 hour" action Function(Time.one_hour_advance)
You have to take out the brackets basically. Meanwhile if you have arguments for your function, you can pass them as arguments from the second argument onwards. I can't remember if you need to name your arguments when you pass them, but I tend to do them out of habit for easy reference later.
I tried using the code line but for some weird reason the game is not doing whatever the class method is supposed to do but instead jumps to another label even though i never indicated to do that in the code.
False alarm i was so stupid... i was calling the other thing myself, i deleted it and now it is not jumping to that label... i had a call to a screen and i wasn't even aware of it hahaha.
Still my function does not increase the time i'll do more checking.
label start:
"[Time.time]" # or whatever the attribute is to get the current time
call screen menu
"[Time.time]" # check if the time has increased
return
label start:
"[Time.time]" # or whatever the attribute is to get the current time
call screen menu
"[Time.time]" # check if the time has increased
return
Hmmm, how can i just add a button that increases the time and just does that without the need to do anything like that?
I checked the way you suggested and it is actually working but i need to stay in the game after increasing the time and not just going to the main menu.
You just need to add content to the game, put whatever needs to happen next in the game - the time has advanced, you just need to write the rest of the game.