Page 1 of 1

Help with SensitiveIf() command?

Posted: Wed Mar 18, 2020 6:58 pm
by Samitha
Hello :D!

I was browsing the forums for some help on making a button have multiple actions and found this: viewtopic.php?t=37185
So I decided to apply the same logic to my own button but it didn't work.

I'm trying to get my button to be sensitive to a specific condition: having a gallery image unlocked. So I found the SensitiveIf() command, but I end up getting an error. The code I used for my button is:

Code: Select all

imagebutton auto "gui/gallery/replay_%s.png" action SensitiveIf[SetVariable("persistent.unlock_cg1", True), Replay("start")]


And the error I got is this:

Code: Select all

I'm sorry, but an uncaught exception occurred.

After initialization, but before game start.
  File "game/screens.rpy", line 1184, in prepare_screen
    screen cg_gallery_extras():
  File "game/screens.rpy", line 1184, in prepare
    screen cg_gallery_extras():
  File "game/screens.rpy", line 1239, in prepare
    grid 2 3:
  File "game/screens.rpy", line 1239, in prepare
    grid 2 3:
  File "game/screens.rpy", line 1251, in prepare
    imagebutton auto "gui/gallery/replay_%s.png" action SensitiveIf[SetVariable("persistent.unlock_cg1", True), Replay("start")]
  File "game/screens.rpy", line 1251, in prepare
    imagebutton auto "gui/gallery/replay_%s.png" action SensitiveIf[SetVariable("persistent.unlock_cg1", True), Replay("start")]
TypeError: 'type' object has no attribute '__getitem__'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "C:\Program Files\renpy-7.2.2-sdk\renpy\bootstrap.py", line 313, in bootstrap
    renpy.main.main()
  File "C:\Program Files\renpy-7.2.2-sdk\renpy\main.py", line 525, in main
    run(restart)
  File "C:\Program Files\renpy-7.2.2-sdk\renpy\main.py", line 90, in run
    renpy.display.screen.prepare_screens()
  File "C:\Program Files\renpy-7.2.2-sdk\renpy\display\screen.py", line 909, in prepare_screens
    s.ast.prepare_screen()
  File "game/screens.rpy", line 1184, in prepare_screen
    screen cg_gallery_extras():
  File "game/screens.rpy", line 1184, in prepare
    screen cg_gallery_extras():
  File "game/screens.rpy", line 1239, in prepare
    grid 2 3:
  File "game/screens.rpy", line 1239, in prepare
    grid 2 3:
  File "game/screens.rpy", line 1251, in prepare
    imagebutton auto "gui/gallery/replay_%s.png" action SensitiveIf[SetVariable("persistent.unlock_cg1", True), Replay("start")]
  File "game/screens.rpy", line 1251, in prepare
    imagebutton auto "gui/gallery/replay_%s.png" action SensitiveIf[SetVariable("persistent.unlock_cg1", True), Replay("start")]
  File "C:\Program Files\renpy-7.2.2-sdk\renpy\python.py", line 1954, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "<screen language>", line 1251, in <module>
TypeError: 'type' object has no attribute '__getitem__'

Windows-8-6.2.9200
Ren'Py 7.2.2.491
Princess Impersonator 1.0
Wed Mar 18 17:42:58 2020
Don't know what I'm doing wrong :lol: :(
Thanks in advance!

Re: Help with SensitiveIf() command?

Posted: Thu Mar 19, 2020 1:59 am
by Per K Grok
Samitha wrote:
Wed Mar 18, 2020 6:58 pm
Hello :D!

I was browsing the forums for some help on making a button have multiple actions and found this: viewtopic.php?t=37185
So I decided to apply the same logic to my own button but it didn't work.

I'm trying to get my button to be sensitive to a specific condition: having a gallery image unlocked. So I found the SensitiveIf() command, but I end up getting an error. The code I used for my button is:

Code: Select all

imagebutton auto "gui/gallery/replay_%s.png" action SensitiveIf[SetVariable("persistent.unlock_cg1", True), Replay("start")]


----

Don't know what I'm doing wrong :lol: :(
Thanks in advance!

The parentheses for action is placed wrong. It should be this way

Code: Select all

imagebutton auto "gui/gallery/replay_%s.png" action [SensitiveIf(SetVariable("persistent.unlock_cg1", True)), Replay("start")]

(I think)

Re: Help with SensitiveIf() command?

Posted: Thu Mar 19, 2020 3:17 am
by shin.e.d
I think SensitiveIf only works with persistent when it's written like this: (otherwise it does nothing.)

Code: Select all

imagebutton auto "gui/gallery/replay_%s.png" action [SensitiveIf(persistent.unlock_cg1==True), Replay("start")]
Also you did have a bracket [ in the wrong place.
Ren'py's code is simliar to python. Square brackets [ ] are used to begin and end a python list. Which has multiple items.
Python list example... backpack = ["book","lunchbox","cat"]
In Ren'py, screen actions can be put in a list to do more than just 1 action.
Ren'py reads it from left -> right. So order matters.

If you'd like your replay button to do a Dissolve() transition to the scene it would look like this:

Code: Select all

imagebutton auto "gui/gallery/replay_%s.png" action [With(Dissolve(1.0)), SensitiveIf(persistent.unlock_cg1==True), Replay("start")]
The With(dissolve) is 1st. But if With(dissolve) was last it won't dissolve. Because if Ren'py does the Replay() action 1st, it won't see With(dissolve) after, as it's stuck replaying.

Though screens apparently don't need brackets [ ] as I saw in the forum post you linked...
only commas. I actually didn't know that... But people seem to still like using brackets anyway.
:3

Re: Help with SensitiveIf() command?

Posted: Wed Mar 25, 2020 12:47 pm
by Samitha
Thank you both for your replies!

The one method that worked was shin.e.d's:
shin.e.d wrote:
Thu Mar 19, 2020 3:17 am
I think SensitiveIf only works with persistent when it's written like this: (otherwise it does nothing.)

Code: Select all

imagebutton auto "gui/gallery/replay_%s.png" action [SensitiveIf(persistent.unlock_cg1==True), Replay("start")]
And I added the dissolve too 'cause I think it looks better :o

Also, thanks for the brief explanation on brackets, I am still a newbie and didn't quite know actions could be thought of as dictionaries. I really can't thank you enough :D And I'm glad we both learned something out of this :D (?)!