I’m writing a mod for a Ren’Py game that includes possibility to edit game’s variables’ values (“cheating”). Variables in the game include different ones from simple booleans to pretty complex ones (e.g simple_variable, obj.attr, obj.attr_a(“some_id”).attr_b). Here’s a function I’m using to set new values to the variables/attributes (var_name is variable’s name as a string and new_val is a value I’m trying to set):
def icmod_set_var_val(var_name, new_val):
_list = var_name.split('.')
o = globals()[_list[0]]
if len(_list) == 1:
o = new_val
elif len(_list) == 2:
setattr(o, _list[1], new_val)
elif len(_list) == 3:
between_quotes = _list[1].split('"')[1::2][0]
first_attr = _list[1].split('[')[0]
_x = getattr(o, first_attr)[between_quotes]
setattr(_x, _list[2], new_val)
else:
msgs.show('Something went wrong')
It doesn’t work. When I’m using similar function to display modified values (using getattr) they’re showing correctly. But when I use console or save a game and open it again I can see that the values are not actually changed. I even tried to use exec to change the values, but that doesn’t seem to have a permanent effect either. So what am I doing wrong or missing here?
2