Setting two variables with one button?

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.
Post Reply
Message
Author
Cristiander
Regular
Posts: 33
Joined: Sat Mar 04, 2017 8:19 am
Contact:

Setting two variables with one button?

#1 Post 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?

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Setting two variables with one button?

#2 Post 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...
    

Cristiander
Regular
Posts: 33
Joined: Sat Mar 04, 2017 8:19 am
Contact:

Re: Setting two variables with one button?

#3 Post 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

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Setting two variables with one button?

#4 Post 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)]
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Setting two variables with one button?

#5 Post 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:)

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Setting two variables with one button?

#6 Post by Ocelot »

Current implementation works woth any iterable containing Actions. Tuple in this case.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot]