Conditional imagebutton [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
HammeredEnt
Regular
Posts: 33
Joined: Sat May 04, 2019 8:09 am
Contact:

Conditional imagebutton [SOLVED]

#1 Post by HammeredEnt »

Hi team,

It's late and I'm probably just plain missing what's glaringly obvious to everyone else, but I'm trying to make a conditional imagebutton work and it's throwing a hissyfit.

imagebutton auto "phonewatch_%s.png" action If("time <= 3", AddToSet(time, 1), Jump("sallybed")) align (0.01,0.04)

I have a variable for time ("default time = 0" in the pre-start definitions) which, if clicked, the imagebutton should add one to. Once the time variable raises to 4 and the imagebutton is clicked again, it should jump to the 'sallybed' label in the script.

When trying to run it like that, I get:

I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/loc-stbedroom.rpy", line 253, in script
scene bg stbathroom with dissolve
File "renpy/common/00action_data.rpy", line 411, in get_sensitive
return self.value not in self.set
TypeError: argument of type 'int' is not iterable


Is it the "time <= 3" section or the AddToSet bit that I'm getting wrong? I thought AddTOSet was right for simply advancing a numerical counter but could be way off there...

Thanks!
Last edited by HammeredEnt on Wed Jan 29, 2020 5:44 am, edited 1 time in total.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Conditional imagebutton

#2 Post by Remix »

What is time? A set or an int?

Code: Select all

default time = 0

screen a():
    imagebutton auto "phonewatch_%s.png" action If(time <= 3, SetVariable('time', time+1), Jump("sallybed")) align (0.01,0.04)
Maybe?
Frameworks & Scriptlets:

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Conditional imagebutton

#3 Post by gas »

AddToSet is for other types than ints (it append that value to the end of a list or set).
You need SetVariable("time", time+1).

(Sorry, I wrote it the same exact moment the above reply!)
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

HammeredEnt
Regular
Posts: 33
Joined: Sat May 04, 2019 8:09 am
Contact:

Re: Conditional imagebutton

#4 Post by HammeredEnt »

Thanks to both of you for replying! Yes, time was an int, so the amendment to SetVariable was just the guidance I needed to get that aspect working.

However, while it's functioning, it's not being conditional - it just keeps running true regardless of the "time" variable being at 4 or higher.

action If("time <= 3", SetVariable("time", time+1), Jump("sallybed"))

Have I got my syntax wrong somewhere? I tried swapping around the true and false returns and it kept doing the same thing of running the true return.

User avatar
Angelo Seraphim
Regular
Posts: 36
Joined: Tue May 21, 2019 8:00 am
Completed: Enamored Risks (NaNoReNo 2020)
Projects: 616 Charagma
Organization: GLSUoA
Deviantart: glsuoa
itch: glsuoa
Location: London, UK
Discord: Just A Concept#9599
Contact:

Re: Conditional imagebutton

#5 Post by Angelo Seraphim »

Should be:

Code: Select all

action If(time <= 3, SetVariable("time", time + 1), Jump("sallybed"))
time <= 3 without the quotes. (That's probably with it's running "true" all the time.)

So just a quick summary;
time <= 3 :: time has to be less than or equal to 3 to be true, otherwise it will be false.
Image

HammeredEnt
Regular
Posts: 33
Joined: Sat May 04, 2019 8:09 am
Contact:

Re: Conditional imagebutton

#6 Post by HammeredEnt »

Ah-hah! That was it, thank you! Thanks everyone for their help with this!

Post Reply

Who is online

Users browsing this forum: No registered users