How to change a list value with an imagebutton

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
nunyabeezwax
Newbie
Posts: 1
Joined: Sat Jan 09, 2021 9:55 am
Contact:

How to change a list value with an imagebutton

#1 Post by nunyabeezwax »

Is it possible to change the value in a list via an imagebutton? I figured out that you can use SetVariable, but I'm wondering if there's something like SetVariableList

Code: Select all

default player1POS= [0,0]

screen demo:
    vbox xalign 0.125 yalign 0.682:
        imagebutton:
            idle "images/neutral.png"
            hover "images/positive.png"
            action SetVariable(CHANGE SPECIFIC LIST VALUE HERE), Jump("start")
            
label start:
	call screen demo

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: How to change a list value with an imagebutton

#2 Post by _ticlock_ »

Hi, nunyabeezwax,

I am not sure if there is a better way to do it, but you can always use Function:

Code: Select all

init python:
    def set_list(list_var, indx, new_value):
        list_var[indx] = new_value

default list_var = [1,2]

screen test():
    vbox:
        imagebutton idle Text(str(list_var[0])):
            xsize 100 ysize 100
            action Function(set_list, list_var, 0, list_var[0]+1)
        imagebutton idle Text(str(list_var[1])):
            xsize 100 ysize 100
            action Function(set_list, list_var, 1, list_var[1]+10)
label start:
    call screen test

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to change a list value with an imagebutton

#3 Post by Remix »

You could also use integer keys with SetDict btw

Code: Select all

        #             dict-or-list, key, value
        action SetDict( player1POS, 0, 40 ) 
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Black Spriggan, Ocelot, snotwurm