What am I doing wrong?
As often the Python errors tell pretty much. Unfortunately they do not necessarily match what we expect. So it is pretty easy to miss the important content of the message.
Luckily when you read the error text twice or more you can get an idea what the problem is.
So here is an insight:
(you can ignore the stack trace at that stage):
key not in list
as simple as it sounds ...
there is a list.
there is an access by key.
this key is not in this list.
Here it is the specific key used at that operation
The code tries tho access a list by key "restriction". The error tells there is no item with key "restriction".
Where did it happen?
Python code can be used at various different Python controllers. The error occurred at a specific one. Often you need the context of the controller to investigate into the error situation. For example the owning object misses a property, while it is present at another object.
Unfortunately you skipped that line. So I show you a sample from my file:
Python script error - object 'Cube', controller 'Python':
This is important info:
The owning object (owner) is called "Cube"
The controller is called "Python"
Now you know the context.
Here you need the stack trace. The last entry tells you what file and what line of that file causes the error.
Be aware if there are several operations at that line, it can't tell you. Therefore it is a good idea to have as less operations as possible at a single line. Just in case there is an error with one of them.
This is typically a textblock - in your case text block "Untitled"
(Hint: a more descriptive name will help you later).
The line in the source code
This means you are running in script mode ... there is no explicit module to name. Therefore it is called . You can ignore it.
Now you know where to look a the code.
Line 18 of "Untitled" is:
obj0 = scene.objectsInactive['restriction']
You know from the information above that "restriction is not in a list. The list is not named in the error message. So we check the source code to identify lists.
There is only one list:
We can conclude: There is no item with key "restriction".
What do we know about that objectsInactive?
A list of objects on background layers (used for the addObject actuator), (read-only)
Not really helpful as there are no "background layers" in the BGE. The name "objectsInactive" is more helpful here. It is a list of inactive objects.
When you have a bit of experience with the BGE, then you learned that you can access items from the list via name. That is what you did.
So you can conclude
-> There is no object called "restriction" in the list of inactive objects
-> There is no inactive object "restriction" in the scene.
-> There is no object "restriction" at an hidden layer of the current scene
I suggest you check your file if that is the case.
Maybe the layer this object is living in is enabled.
- -> disable the layer
Maybe you wanted to access active objects
- -> in your code change
- -> in your code change
I hope this helps