Page 1 of 1

Conditional imagebutton [SOLVED]

Posted: Tue Jan 28, 2020 8:57 am
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!

Re: Conditional imagebutton

Posted: Tue Jan 28, 2020 9:36 am
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?

Re: Conditional imagebutton

Posted: Tue Jan 28, 2020 9:39 am
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!)

Re: Conditional imagebutton

Posted: Wed Jan 29, 2020 5:11 am
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.

Re: Conditional imagebutton

Posted: Wed Jan 29, 2020 5:24 am
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.

Re: Conditional imagebutton

Posted: Wed Jan 29, 2020 5:44 am
by HammeredEnt
Ah-hah! That was it, thank you! Thanks everyone for their help with this!