Page 1 of 1

Setting two variables with one button?

Posted: Sun Jan 14, 2018 6:32 am
by Cristiander
Is it possible to set the values of two variables with the same button?

I have a simple inventory system and I want to have it so that when the player uses an item it changes a variable (say he's hp or mp) and then have the item disappear from the inventory (since it was used).

But the action propriety only allows one variable to be changed.
Is there a way around this?

Re: Setting two variables with one button?

Posted: Sun Jan 14, 2018 7:11 am
by IrinaLazareva
it is possible to add several functions on one action
for example

Code: Select all

    textbutton "Press Me" action SetVariable(hp', hp+1), SetVariable('mp', mp+1), SetVariable('var3', 0) #etc...
    

Re: Setting two variables with one button?

Posted: Sun Jan 14, 2018 10:17 am
by Cristiander
IrinaLazareva wrote: Sun Jan 14, 2018 7:11 am it is possible to add several functions on one action
for example

Code: Select all

    textbutton "Press Me" action SetVariable(hp', hp+1), SetVariable('mp', mp+1), SetVariable('var3', 0) #etc...
    
I see. I didn't know that :))
Thank you very much

Re: Setting two variables with one button?

Posted: Sun Jan 14, 2018 1:37 pm
by xavimat
IrinaLazareva wrote: Sun Jan 14, 2018 7:11 am

Code: Select all

    textbutton "Press Me" action SetVariable(hp', hp+1), SetVariable('mp', mp+1), SetVariable('var3', 0) #etc...    
Is this working?
I've seen usually lists of actions to do this, with []
An action may also be a list of actions, in which case the actions in the list are run in order.
From the doc: https://www.renpy.org/doc/html/screen_a ... ml#actions

Code: Select all

    textbutton "Press Me" action [SetVariable('hp', hp+1), SetVariable('mp', mp+1), SetVariable('var3', 0)]

Re: Setting two variables with one button?

Posted: Sun Jan 14, 2018 1:59 pm
by IrinaLazareva
xavimat wrote: Sun Jan 14, 2018 1:37 pm Is this working?
I've seen usually lists of actions to do this, with []
Yes. It is.
Usually, I use [] - sign only if it is necessary to make transfer of a line.

Code: Select all

    textbutton "" action [Show(), 
        SetVariable(), 
        Function(),
        ]

P.S. Though I can be mistaken. I don't claim that it is correct. Just it works. O:)

Re: Setting two variables with one button?

Posted: Sun Jan 14, 2018 2:21 pm
by Ocelot
Current implementation works woth any iterable containing Actions. Tuple in this case.