join string and number variables (or convert variable types)

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
User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

join string and number variables (or convert variable types)

#1 Post by Kia »

I never taught this will become a problem for me but I have difficulty put to type of variables together and I can't find how to convert "int" to "string".
this line of code:

Code: Select all

text "Day:" + "[curday]" size 10 anchor(0.5, -0.5)
works fine for some reason but when I try to do it in:

Code: Select all

imagebutton anchor(0.5, 0.5) idle "ui/clock/timer1.png" hover "ui/clock/timer1.png" focus_mask True action SetVariable('daycalc', "Day:" + curday)
it suddenly remembers that the variables have different type.
the "string()" function wont work either. apparently its not included in syntax or something.

nintendotoad
Regular
Posts: 42
Joined: Sat Mar 31, 2012 2:56 pm
Location: projectexist.net
Contact:

Re: join string and number variables (or convert variable ty

#2 Post by nintendotoad »

https://docs.python.org/2/library/functions.html#str

Does str() work? It does on my end.

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: join string and number variables (or convert variable ty

#3 Post by Kia »

the error is gone but it's not doing anything :? here is the screen that contains this problem

Code: Select all

screen g_time:
    window id "wndw" xysize(0, 0) pos(900, 100):
        imagebutton anchor(0.5, 0.5) idle "ui/clock/timer1.png" hover "ui/clock/timer1.png" focus_mask True action SetVariable('daycalc', "Day:" + str(curday))
        #add "ui/clock/timer1.png" anchor(0.5, 0.5)
        add "ui/clock/timer.png"  at rotateshort
        text "[timcalc]" size 15 anchor(0.5, 0.5)
        text "[daycalc]" size 10 anchor(0.5, -0.5)
show screen g_time

nintendotoad
Regular
Posts: 42
Joined: Sat Mar 31, 2012 2:56 pm
Location: projectexist.net
Contact:

Re: join string and number variables (or convert variable ty

#4 Post by nintendotoad »

I have no idea what "it's not doing anything" means. As far as I know, it could mean any of the following:
* the variable 'daycalc' doesn't get changed at all
* the variable 'daycalc' is changed, but is only changed to "Day:" because str() itself isn't working
* the variable 'daycalc' is changed, but the player doesn't know that because the screen doesn't show the new value of 'daycalc'
* the screen doesn't even appear anymore

In any case, the below code seems to function as intended; upon clicking on the textbutton, the text immediately changes from 'sandwich' to 'Day:15'. In other words, on Ren'Py 6.17.7.521, I can't replicate your issue. Are there any other functions (especially callbacks) that are changing 'daycalc' or 'curday'?

Code: Select all

screen why_now:
    textbutton "wait" action SetVariable('daycalc', "Day:" + str(curday))
    text "[daycalc]"

label start:
    $ daycalc = "sandwich"
    $ curday = 15
    show screen why_now
    "wait here"

Post Reply

Who is online

Users browsing this forum: Google [Bot]