Page 1 of 1

Variable Buttons

Posted: Wed Oct 06, 2010 11:22 am
by liude
Some time ago I posted asking how to create a menu linking to other game menus to replace the standard game menu. Now i got involved in a project where it became necesary to print variables inside a button and have it update whenever the variable is changed. Of course, this could be done through the use of if/else statements...

If only it was that easy. Problem is, the variable is the result of renpy.input(), and I cant limit nor foresee what values will be added to the variable by the user (name input code, can be whatever the user wants).

What I tried:
- Setting the button text as "%(var)s". Doesnt work, text on the buttom is the code itself, not the value nor "< var unbound >".
- Saving the value as persistent data and calling it as ui.text() on a background that matches the location of the button. Returns same problems as the other attempt.

Thanks in advance.

Re: Variable Buttons

Posted: Wed Oct 06, 2010 12:00 pm
by Aleema
If your variable is a string, you can just set the button text to it, no %()s involved.
ui.textbutton(var, clicked=...)
If it's an integer (number) you can do it that way, or:
ui.textbutton("%d"%var, clicked=...)

Re: Variable Buttons

Posted: Wed Oct 06, 2010 12:46 pm
by liude
Works great, tyvm for fast reply.