[Solved]Showing variables correctly in an action - string

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
Chekhov
Regular
Posts: 113
Joined: Tue Jun 26, 2018 9:19 am
Projects: Pluton
Contact:

[Solved]Showing variables correctly in an action - string

#1 Post by Chekhov »

The two for loops create an isometric grid of tiles.

I don't know how to correctly show the variables inside the string on the last line.

Code: Select all


define boardsize = [5,8]
define showcoordinates = False

screen Gameboard():
    fixed:
        xpos 300 ypos 400
	for y in range(boardsize[0]):
            for x in range(boardsize[1]):
                fixed:
                    xysize (200, 100)
                    xoffset ((x * 163) + (y * -30))
                    yoffset (y * 100)
                    add "tile.png" xalign 0.0 yalign 0.0
                    imagebutton:
                        idle "tile"
                        hover "tile-select"
                        action Notify(_("You clicked tile [x], [y]"))
                        #How do I make the line above use the variables of x and y at the time of creation?
Last edited by Chekhov on Fri Sep 13, 2019 4:59 pm, edited 1 time in total.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Showing variables correctly in an action - string

#2 Post by hell_oh_world »

Chekhov wrote: Fri Sep 13, 2019 2:38 pm The two for loops create an isometric grid of tiles.

I don't know how to correctly show the variables inside the string on the last line.

Code: Select all


define boardsize = [5,8]
define showcoordinates = False

screen Gameboard():
    fixed:
        xpos 300 ypos 400
	for y in range(boardsize[0]):
            for x in range(boardsize[1]):
                fixed:
                    xysize (200, 100)
                    xoffset ((x * 163) + (y * -30))
                    yoffset (y * 100)
                    add "tile.png" xalign 0.0 yalign 0.0
                    imagebutton:
                        idle "tile"
                        hover "tile-select"
                        action Notify(_("You clicked tile [x], [y]"))
                        #How do I make the line above use the variables of x and y at the time of creation?
You can interpolate just like what you did or use format() function to make it less messy.

Code: Select all

action Notify(_("You clicked tile {}, {}".format(x, y)))

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Showing variables correctly in an action - string

#3 Post by namastaii »

Try

Code: Select all

action Notify(_("You clicked tile {}, {}").format(x,y))
edit: I didn't see your response before me XD

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Showing variables correctly in an action - string

#4 Post by hell_oh_world »

namastaii wrote: Fri Sep 13, 2019 4:34 pm Try

Code: Select all

action Notify(_("You clicked tile {}, {}").format(x,y))
edit: I didn't see your response before me XD
Well, it happens :D :D . Just in the nick of time :lol:

User avatar
Chekhov
Regular
Posts: 113
Joined: Tue Jun 26, 2018 9:19 am
Projects: Pluton
Contact:

Re: Showing variables correctly in an action - string

#5 Post by Chekhov »

namastaii wrote: Fri Sep 13, 2019 4:34 pm Try

Code: Select all

action Notify(_("You clicked tile {}, {}").format(x,y))
edit: I didn't see your response before me XD
hell_oh_world wrote: Fri Sep 13, 2019 4:29 pm
Chekhov wrote: Fri Sep 13, 2019 2:38 pm The two for loops create an isometric grid of tiles.

I don't know how to correctly show the variables inside the string on the last line.

Code: Select all


define boardsize = [5,8]
define showcoordinates = False

screen Gameboard():
    fixed:
        xpos 300 ypos 400
	for y in range(boardsize[0]):
            for x in range(boardsize[1]):
                fixed:
                    xysize (200, 100)
                    xoffset ((x * 163) + (y * -30))
                    yoffset (y * 100)
                    add "tile.png" xalign 0.0 yalign 0.0
                    imagebutton:
                        idle "tile"
                        hover "tile-select"
                        action Notify(_("You clicked tile [x], [y]"))
                        #How do I make the line above use the variables of x and y at the time of creation?
You can interpolate just like what you did or use format() function to make it less messy.

Code: Select all

action Notify(_("You clicked tile {}, {}".format(x, y)))
Very nice, thank you both!

Post Reply

Who is online

Users browsing this forum: No registered users