2
$\begingroup$

I am making a game with BGE. It is turn based, so I want to save a sequence of key strokes in a list. The problem is that the list is not preserved the next time a key stroke is entered, as the script is run on every key event.

My logic: enter image description here

The way I have solved this til now is to convert the list to a JSON string and save it as a string property. However this is a very dirty way to do something like this.

How can I do this in a nice elegant way?

$\endgroup$

1 Answer 1

1
$\begingroup$

You will have to define the list in the script like this:

if 'list' not in object:
    object['list'] = []

You can then add objects using functions such as

object['list'].append('x') # adds the string 'x' to the end
object['list'].instert(3, 'x') # adds the string 'x' at position 3
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.