Help with SensitiveIf() command?

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
Samitha
Newbie
Posts: 16
Joined: Wed Nov 13, 2019 5:21 pm
Projects: Princess Impersonator
itch: samitha-games
Contact:

Help with SensitiveIf() command?

#1 Post 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!

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Help with SensitiveIf() command?

#2 Post 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)

User avatar
shin.e.d
Newbie
Posts: 22
Joined: Sat Jan 10, 2015 10:50 am
Projects: Data Lion and an unnamed bxb game with dinosaurs!
Contact:

Re: Help with SensitiveIf() command?

#3 Post 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

User avatar
Samitha
Newbie
Posts: 16
Joined: Wed Nov 13, 2019 5:21 pm
Projects: Princess Impersonator
itch: samitha-games
Contact:

Re: Help with SensitiveIf() command?

#4 Post 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 (?)!

Post Reply

Who is online

Users browsing this forum: No registered users