"dynamic" variables cause KeyError at return

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
rivvil
Regular
Posts: 26
Joined: Fri Feb 20, 2015 3:05 pm
Location: Russia
Contact:

"dynamic" variables cause KeyError at return

#1 Post by rivvil » Sat Mar 07, 2015 3:51 pm

Hi again.
I don't know whether it is feature or bug but if I would write something like this:

Code: Select all

label test:
    renpy.dynamic('a')
    return
and call label "test" when variable "a" is undefined, then at "return" statement method pop_dynamic (execution.py, line 210) would raise KeyError trying to del undefined attribute "a" from the store. If variable "a" was defined before the call, no exception raised. It seems like not a very consistent behavior.
Personally I would prefer to be able to "declare" all variables, that might be used within callable label, at once and do not care lately whether I assign them or not.
To achieve this It's possible to add simple "in" check into for loop within pop_dynamic() method:

Code: Select all

for k, v in dynamic.iteritems():
    if isinstance(v, Delete):
        if k in store: # check if dynamic variable was assigned
            del store[k]
    else:
        store[k] = v
So, is it a feature or bug that I must to assign every "dynamic" variable?
PS. Sorry for my English... It's rather difficult for me to express my thoughts. Hope you will be able to understand.

Post Reply

Who is online

Users browsing this forum: No registered users