Using SetVariable for counters? [solved]

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
User avatar
noeinan
Eileen-Class Veteran
Posts: 1126
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Using SetVariable for counters? [solved]

#1 Post by noeinan » Wed Feb 01, 2017 8:42 pm

I'm trying to get a button action that will take a variable, say, time_cnt, and then set that variable to time_cnt + 1.

However, it seems to me that SetVariable accepts variables as a string and does not take in their value? Or at least I haven't had much success figuring it out... Is it possible to use SetVariable as a time counter? And if so, what is the proper syntax of that?

This is what I tried, but it didn't work:

Code: Select all

SetVariable("time_cnt", time_cnt + 1)
Last edited by noeinan on Thu Feb 02, 2017 4:28 pm, edited 1 time in total.
Image

Image
Image

neowired
Regular
Posts: 199
Joined: Mon Dec 01, 2008 2:33 pm
Contact:

Re: Using SetVariable for counters?

#2 Post by neowired » Wed Feb 01, 2017 9:28 pm

Code: Select all

textbutton "[varA]" action SetVariable('varA',varA+1)
This definitely works, you must be getting an error somewhere else. (Of course you also need to declare the variable first)

User avatar
noeinan
Eileen-Class Veteran
Posts: 1126
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Using SetVariable for counters?

#3 Post by noeinan » Thu Feb 02, 2017 4:25 pm

neowired wrote:

Code: Select all

textbutton "[varA]" action SetVariable('varA',varA+1)
This definitely works, you must be getting an error somewhere else. (Of course you also need to declare the variable first)

When I added only that, it gave me an error, then I removed it and it started working again. Now I just tried it again and suddenly it works? XD No idea why, but I'm not complaining. I must have had a typo somewhere.
Image

Image
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]