Weird textbutton action bug

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
jeffc
Newbie
Posts: 2
Joined: Tue Feb 20, 2018 8:45 am
Contact:

Weird textbutton action bug

#1 Post by jeffc »

So I created a simple test shopping screen with one "Buy" textbutton for buying things.
The buyItem function is supposed to be called only when the textbutton is clicked, but somehow the textbutton's action is triggered automatically the moment the screen is shown, even though the textbutton was never clicked.
I know for certain that the function was called because some variables that I watch in the debug console changed in value when the screen is called.

The screen is shown using the call screen statement:

Code: Select all

call screen test
The screen code:

Code: Select all

screen test:
    add "#000"
    modal True
    default button_caption = "Buy"
    vbox:
        textbutton "[button_caption]" action [SetScreenVariable("button_caption","Bought"),buyItem(shopping_item_code, 20)]
        textbutton "Back" action [Hide("test"),Return]
And the main python script:

Code: Select all

init python:
    def buyItem(itemCode, itemCost):
    	#change some variable values
Am I missing something here? I thought handling textbutton clicks are supposed to be straightforward, but I can't figure out what is causing the problem.

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: Weird textbutton action bug

#2 Post by Remix »

Use the action "Function()"

Code: Select all

textbutton "[button_caption]" action [SetScreenVariable("button_caption","Bought"), Function( buyItem, shopping_item_code, 20 ) ]
Frameworks & Scriptlets:

jeffc
Newbie
Posts: 2
Joined: Tue Feb 20, 2018 8:45 am
Contact:

Re: Weird textbutton action bug

#3 Post by jeffc »

Thanks Remix for your suggestion. It works perfectly now.
Man, the official documentation really should highlight these kinds of small nuances in the code. There's no mention of Function in the Screens and Screen Language page.


Post Reply

Who is online

Users browsing this forum: AWizardWithWords, Ocelot