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 » Sun Jan 14, 2018 6:32 am

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: 272
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy, Эра Тёмных Небес
Organization: IKG
Location: St.Petersburg, Russia
Contact:

Re: Setting two variables with one button?

#2 Post by IrinaLazareva » 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...
    
There is a light at the end of the tunnel, just pray it's not a train.
___
TODO: unresolved/нерешённое

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

Re: Setting two variables with one button?

#3 Post by Cristiander » Sun Jan 14, 2018 10:17 am

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: 1337
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: xavimat
Location: Italy
Contact:

Re: Setting two variables with one button?

#4 Post by xavimat » Sun Jan 14, 2018 1:37 pm

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)]
Cops&Robbers A two-player experiment
Fear&Love Why can’t we simply express our feelings? Why am I afraid to say ‘I love you’?
unknown [Sci-Fi - mystery - computer]
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
IrinaLazareva
Veteran
Posts: 272
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy, Эра Тёмных Небес
Organization: IKG
Location: St.Petersburg, Russia
Contact:

Re: Setting two variables with one button?

#5 Post by IrinaLazareva » Sun Jan 14, 2018 1:59 pm

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:)
There is a light at the end of the tunnel, just pray it's not a train.
___
TODO: unresolved/нерешённое

User avatar
Ocelot
Miko-Class Veteran
Posts: 849
Joined: Tue Aug 23, 2016 10:35 am
Skype: miinipaa
Contact:

Re: Setting two variables with one button?

#6 Post by Ocelot » Sun Jan 14, 2018 2:21 pm

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: IaMe