array(list?) property


How can I define an array. My problem is I can say array = [1,2,3], but if I change the values in the array now say array[0]=5 the array[0] gets set back to 1 every time the code runs. For int, or float I can set them as object property and that seems to work. Not much of a programmer so any advice would be appreciated.

Sorry, double post. See below post.

Try defining the array as a GameLogic variable, ie:

array = GameLogic.array #tests if is already exists
array = [1,2,3] #if it doesn't exist, create it
# The rest of your code here
GameLogic.array = array #Be sure to assign your array variable to the GameLogic.array variable at the end of the script

Hopefully that makes sense to you.


Your indentation will generate an error. Also, declaring a local list on “except:” is somewhat pointless in this case. It’s the global list that you’ll use anyway, so just declare that on except, and get rid of “GameLogic.array = array”.


Only global objects and properties retain memory after a script pass. Everything else is flushed.

Here, take a look at this example:

I think I understand what is going on here. You can use python to add a property to the GameLogic. When the new property is not recognized an exception is thrown and the new property is given a definition.

Why do you typecast the new GameLogic property? Also, thankyou for taking the time to make a small blend.

I should say I also came up with:
array = [obj.0,obj.1,obj.2,etc.] which works for the smaller arrays.

Force of habit (because “debug” is a a string property, so I try to give it what it takes). It’s not necessary though, because just doing “own.debug = g.list” will work fine (when setting to a prop, it’s converted by default).