Ren'Py Lab Rats 2 - action SetField / SetDict / SetVariable? [Solved]

Trollden

Member
Aug 8, 2017
253
326
First of all, sorry if I have the terminologies wrong and I don't mind being corrected.
This may be a very simple thing to solve, but I don't have 200 IQ.

I am stuck on how to utilize an "action" to edit a "variable". I think the correct thing to call it is a dictionary key?

What I am attempting to achieve is to increase / decrease the value of a dictionary key called "Foreplay" in mc.sex_skills by left click and right clicking a textbutton.

This is how MC is setup by the game creator in script.rpy.

Code:
## shortname for class is mc
class MainCharacter(renpy.store.object):
        def __init__(self, location, name, last_name, business, stat_array, skill_array, sex_array):

# [...] variables

##Sex Skills##
            # These skill represent your knowledge and experience with different types of intimacy. Useful for raising a girls arousal faster than your own.
            self.sex_skills = {}
            self.sex_skills["Foreplay"] = sex_array[0] # A catch all for everything that goes on before blowjobs, sex, etc. Includes things like kissing, massages, etc.
            self.sex_skills["Oral"] = sex_array[1] # Your skill at eating a girl out.
            self.sex_skills["Vaginal"] = sex_array[2] # Your skill at different positions that involve vaginal sex.
            self.sex_skills["Anal"] = sex_array[3] # Your skill skill at different positions that involve anal sex.
To edit other variables, e.g stamina, arousal, intelligence I do the following:


Code:
        vbox:
                textbutton "Main Stats" action NullAction() style "cheatbutton_style" text_style "textbutton_text_style" xsize 220 # Handles the player's main stats

                textbutton "Charisma: [mc.charisma]" action SetField(mc,"charisma", mc.charisma + 1) alternate SetField(mc,"charisma", mc.charisma - 1)  style "cheatbutton_style" text_style "cheattext_style" xsize 220
                textbutton "Intelligence: [mc.int]" action SetField(mc,"int", mc.int + 1) alternate SetField(mc,"int", mc.int - 1) style "cheatbutton_style" text_style "cheattext_style" xsize 220
                textbutton "Focus: [mc.focus]" action SetField(mc,"focus", mc.focus + 1) alternate SetField(mc,"focus", mc.focus - 1) style "cheatbutton_style" text_style "cheattext_style" xsize 220
                textbutton "Stamina: [mc.current_stamina]" action [SetField(mc,"max_stamina", mc.max_stamina + 1), SetField(mc,"current_stamina", mc.max_stamina + 1)] alternate [SetField(mc,"max_stamina", mc.max_stamina - 1), SetField(mc,"current_stamina", mc.max_stamina - 1)] style "cheatbutton_style" text_style "cheattext_style" xsize 220 # Updates the current stamina to match the maximum stamina that the player has.
SetField works fine for normal variables, but sex_skills seems to be a list or dictionary? And I can't get it to set the values by using actions.

i've been trying SetField, SetVariable and SetDict, but I can't get it to work.

What I want the outcome to be is the same as when I use SetField, but replace SetField with whatever is necessary for it to work (e.g SetVariable, SetDict or anything else I am unaware of).

When it comes to SetDict I'm thinking it should be something like:
Code:
action SetDict (mc.sex_skills, Foreplay, +1)

#or

action SetDict (mc.sex_skills, ["Foreplay"], +1)

# I want the value it increases / decreases by to be +1 or -1 of whatever "Foreplay" currently is at
# +=1 or mc.sex_skills["Foreplay"] +=1, but I can't get it to work.
Thanks for any help, and do ask questions if it's unclear.
A possible workaround would be to Call a label that takes care of it using $ mc.sex_skills["Foreplay"] += 1, but I would have to make a new label for every skill, so I would prefer understanding how this works instead.
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,483
6,992
Have you tried
Code:
action SetDict (mc.sex_skills, "Foreplay", mc.sex_skils["Foreplay"] +1)
First argument: the dictionary - you have that correct.
Second argument: The key into the dictionary. Needs to be a string, so just Foreplay won't work, since that assumes Foreplay is a variable containing a string. ["Foreplay"] creates an array that contains the string "Foreplay" - also wrong.
Third argument: the value to which you want to set the dictionary element. Using just "+1" will set it to one, instead of incrementing it by one.
 

Trollden

Member
Aug 8, 2017
253
326
Have you tried
Code:
action SetDict (mc.sex_skills, "Foreplay", mc.sex_skils["Foreplay"] +1)
First argument: the dictionary - you have that correct.
Second argument: The key into the dictionary. Needs to be a string, so just Foreplay won't work, since that assumes Foreplay is a variable containing a string. ["Foreplay"] creates an array that contains the string "Foreplay" - also wrong.
Third argument: the value to which you want to set the dictionary element. Using just "+1" will set it to one, instead of incrementing it by one.
Thank you so much!