Variable Buttons

A place to discuss things that aren't specific to any one creator or game.
Forum rules
Ren'Py specific questions should be posted in the Ren'Py Questions and Annoucements forum, not here.
Post Reply
Message
Author
liude
Newbie
Posts: 16
Joined: Fri Dec 18, 2009 9:42 am
Contact:

Variable Buttons

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

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Variable Buttons

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

liude
Newbie
Posts: 16
Joined: Fri Dec 18, 2009 9:42 am
Contact:

Re: Variable Buttons

#3 Post by liude »

Works great, tyvm for fast reply.

Post Reply

Who is online

Users browsing this forum: No registered users