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.
I'm trying to implement a menu that can only be called when the player has a certain amount of points. If an action is taken, the amount of points, defined as persistent.current_size, should be decreased by 1. However, this subtraction is not taking place. Here is the relevant code:
screen use_action(message="Are you sure you want to use an Action?"):
modal True
window:
style "gm_root"
frame:
style_prefix "confirm"
xfill True
xmargin 200
ypadding 25
yalign .25
vbox:
xfill True
spacing 25
text _(message):
text_align 0.5
xalign 0.5
hbox:
spacing 100
xalign .5
textbutton _("Yes") action [Hide("use_action"), Function(renpy.call,"action_menu"), SetField(persistent,'current_size',persistent.current_size-1), Show("action_display")] #the problem seems to be here, but I am not sure.
textbutton _("No") action [Hide("use_action")]
I test it in-game using a text interpolation after I use an action, but it always remains at 2.
Last edited by Treladon on Sat Jan 06, 2018 7:10 pm, edited 1 time in total.
WIP: The Tasks of Messengers and Guardians - Progress Page Here!
Your syntax and everything seems correct though I have not had time to actually throw a test together. The only *niggles* I can think of that might be messing with it are:
Is it properly finding the old value? Have you tried SetField( persistent, 'current_size', 100 ) with hard coded value? Or store.persistent.current_size to access it?
The statement might run outside of a context and thereby not register the value update until next interact... try adding a RestartStatement() in the actions (note: I have not used that before and the documentation info is not great. It does mention persistent though, so maybe is worth a try)
Not much else I can think of. I've certainly used SetField( persistent, 'key', value ) before and it worked.
Remix wrote: ↑Sat Nov 25, 2017 6:28 am
Your syntax and everything seems correct though I have not had time to actually throw a test together. The only *niggles* I can think of that might be messing with it are:
Is it properly finding the old value? Have you tried SetField( persistent, 'current_size', 100 ) with hard coded value? Or store.persistent.current_size to access it?
The statement might run outside of a context and thereby not register the value update until next interact... try adding a RestartStatement() in the actions (note: I have not used that before and the documentation info is not great. It does mention persistent though, so maybe is worth a try)
Not much else I can think of. I've certainly used SetField( persistent, 'key', value ) before and it worked.
Errilhl wrote: ↑Sat Nov 25, 2017 3:15 am
Not familiar with SetField(), but couldn't you just use a setattr()?
something like
Hey, thanks so much for your responses and sorry for the late reply. Unfortunately, I tried everything each of you suggested, but nothing worked. However, I was able to figure out a solution. Instead of SetField, I used SetVariable and defined the new variable as the first line of the screen: