Ren'Py [SOLVED]Action SetVariable ?

GoldenD

Member
Sep 30, 2018
102
70
I define a variable in script.rpy
Python:
default _test       = ""
# I tried to define in screen, it's the same
Now, in my screen ui (another rpy file), i have textbutton and tooltips.
Python:
screen ui:

    zorder 105

    imagemap:

.../...
    if len(Hero.weapons)>0:
        textbutton "{b}" + findWeaponName(Hero.weapons[0]) + "{/b}"   xpos 815    ypos 940:  #size 35
            action SetVariable("_test", "weapons")    # tried (_test, "weapons") it's the same
            tooltip "Description"
.../...
    $ tooltip = GetTooltip()
    if tooltip:
        text "[tooltip][_test]"  # tried "[tooltip]{}".format(_test) it's the same
_test is always "" if I define "", None if I define None... never assign by SetVariable ?

An idea ?
 

jon95

Member
Game Developer
Sep 29, 2018
176
393
I define a variable in script.rpy
Python:
default _test       = ""
# I tried to define in screen, it's the same
Now, in my screen ui (another rpy file), i have textbutton and tooltips.
Python:
screen ui:

    zorder 105

    imagemap:

.../...
    if len(Hero.weapons)>0:
        textbutton "{b}" + findWeaponName(Hero.weapons[0]) + "{/b}"   xpos 815    ypos 940:  #size 35
            action SetVariable("_test", "weapons")    # tried (_test, "weapons") it's the same
            tooltip "Description"
.../...
    $ tooltip = GetTooltip()
    if tooltip:
        text "[tooltip][_test]"  # tried "[tooltip]{}".format(_test) it's the same
_test is always "" if I define "", None if I define None... never assign by SetVariable ?

An idea ?
if i didn't remember incorrectly SetVariable() should be like this
Python:
SetVariable('test', "weapons")
 
Last edited:

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,382
Code:
SetVariable(_test, "weapons")
Is almost NEVER what you want. That would say "set the variable whose name is currently held in the '_test' variable".

From :
The name argument must be a string, and can be a simple name like "strength", or one with dots separating the variable from fields, like "hero.strength" or "persistent.show_cutscenes".
And you don't want to put your
Code:
default _test       = ""
inside the screen, because that makes _test a screen variable, whereas you almost certainly want a game variable.

And I have no idea what you're trying to accomplish with
Code:
$ tooltip = GetTooltip()
    if tooltip:
        text "[tooltip][_test]"  # tried "[tooltip]{}".format(_test) it's the same
so maybe you could explain a bit more as to what you're trying to do.

However, one thing I'll point out:

From
Ren'Py reserves all names beginning with a single underscore (_). Do not use names beginning with an underscore, as that may cause your game to break in future versions of Ren'Py.
I have no idea if you're running into something along this line, but perhaps you want to repeat your attempts without the leading underscore...
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,964
16,210
I have no idea if you're running into something along this line, but perhaps you want to repeat your attempts without the leading underscore...
I tried at home, and the variable is correctly assigned despite the underscore ; at least with all the 7.x. This despite the fact that _test is used internally.
The problem seem to come from something else located in the "[...]" part of the code.
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,808
24,389
GoldenD did you actually hovered the button after you clicked it at least once?
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,382
I tried at home, and the variable is correctly assigned despite the underscore ; at least with all the 7.x. This despite the fact that _test is used internally.
The problem seem to come from something else located in the "[...]" part of the code.
That doesn't surprise me, but I figured it was worth mentioning...
 

GoldenD

Member
Sep 30, 2018
102
70
Waouh,
I thought it will be the easiest problem of my list !!
Ok, more code :
Python:
default _test = ""   #in script.rpy

.../...

screen ui:

    zorder 105

    imagemap:

        ground  "[PICTURES_INTERFACE]ui.png"

    text "{b}[Hero.combat]{/b}"                         xpos 1010   ypos 32 size 36

    text "{b}[Hero.endurance]{/b}"                      xpos 1007   ypos 64 size 35

.../... just others text like above

    if len(Hero.weapons)>0:

        textbutton "{b}" + findWeaponName(Hero.weapons[0]) + "{/b}" xpos 815 ypos 940:

            action SetVariable(_test, "weapons")

            tooltip "Description

$ tooltip = GetTooltip()

    if tooltip:

         text "{b}{color=#550001}[tooltip][_test]{/color}{/b}" xpos 1100 ypos 980
For the sample, i concat [tooltip] and [_test] just to try if i have "weapons" in [_test].
For real, I need [_test] to know in which section the tooltip is activated (because i have textbutton for weapons, items, spells...).
And for the66, no i haven't click because i just want a tooltip and no action on click.

To be sure, I've tried renaming variable without underscore, same result.
 

GoldenD

Member
Sep 30, 2018
102
70
GoldenD did you actually hovered the button after you clicked it at least once?
I did some tests and suddenly i'm afraid to understand your question : i did a test replacing SetVariable by Call(label) and what I obtain is : my tooltip when i'm hover and then the call label if I click. And then I understand that i have to click to active SetVariable.
But testing with click, my variable stay empty in my tooltip.
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,808
24,389
1st: if you use the above code, the part to show the tooltip isn't even part of your ui screen because of it's indentation.
2nd: action SetVariable(_test, "weapons") still has to be action SetVariable("_test", "weapons")
3rd: if you want to track a variable/object, open the console and use watch.
4th: nevertheless tooltip and SetVariable work as intended:
Python:
default _test = ""

screen tt_test():
    text "_test: [_test]" align (0., 0.)

    vbox align (.5, .5):
        textbutton "Item":
            action SetVariable("_test", "Item")
            tooltip "Description: Item"
        textbutton "Spell":
            action SetVariable("_test", "Spell")
            tooltip "Description: Spell"
        textbutton "Weapon":
            action SetVariable("_test", "Weapon")
            tooltip "Description: Weapon"
        
    $ tooltip = GetTooltip()

    if tooltip:
        vbox align (.5, 0.):
            text tooltip
            text "Description: [_test]"

label start:
    call screen tt_test
 
Last edited:
  • Like
Reactions: GoldenD

GoldenD

Member
Sep 30, 2018
102
70
1st: if you use the above code, the part to show the tooltip isn't even part of your ui screen because of it's indentation.
2nd: action SetVariable(_test, "weapons") still has to be action SetVariable("_test", "weapons")
3rd: if you want to track a variable/object, open the console and use watch.
4th: nevertheless tooltip and SetVariable work as intended:
Python:
default _test = ""

screen tt_test():
    text "_test: [_test]" align (0., 0.)

    vbox align (.5, .5):
        textbutton "Item":
            action SetVariable("_test", "Item")
            tooltip "Description: Item"
        textbutton "Spell":
            action SetVariable("_test", "Spell")
            tooltip "Description: Spell"
        textbutton "Weapon":
            action SetVariable("_test", "Weapon")
            tooltip "Description: Weapon"
       
    $ tooltip = GetTooltip()

    if tooltip:
        vbox align (.5, 0.):
            text tooltip
            text "Description: [_test]"

label start:
    call screen tt_test
1/ it's just an error with copy/paste (one other error higher when I assign tooltip)
2/ like say in first thread, i tested "_test" and "_test" with same result
3/ the process is simple here, and "_test" was just a value to read and directly display, so directly debug was simplest, for me of course
4/ the only difference I see is the use of vbox, so I guess I had to do something wrong that I’m missing. I've to re-read.
Your code works so I class my thread Solved.
Great thanks.