0
$\begingroup$

I am trying to see (printed in the terminal window) a list of all the objects in the game while game is running.

Posted game file on Github

$\endgroup$
0
$\begingroup$

The print statements you have should show the globalDict contents, if it is empty then you will only see {}, once containing values, it would show as -

{'key1': 'Value One', 'key2': 2}

Note that it doesn't have any values unless you add them, bge.logic.globalDict is a user data dictionary, it doesn't contain game engine properties.

As with any python dictionary, you can loop over the contents using dict.items() to get more control over formatting, there is also dict.keys() and dict.values() if you don't want both of them.

import bge

print('globalDict is')
for k,v in bge.logic.globalDict.items():
    print(k,v)
$\endgroup$
  • $\begingroup$ Your code here works in my game, both inside and outside the main function / loop. So apparently I'm trying to get the globalDict to do something it's not made for. When a player adds new objects to the game, I'd assume that the game has a way of keeping track of those objects (on its own, independent of any code I write.) What I am trying to do is access that data, and hopefully be able to change it. I may be trying to go in a completely wrong direction. I simply want to be able to go back in a turn based game and undo the spawning of objects. $\endgroup$ – quazipseudo Oct 27 '17 at 14:28
  • $\begingroup$ Just because a game maintains data doesn't mean it is using the globaldict. The code you linked to only prints the globaldict, it doesn't alter it in any way. Each object can have game properties, maybe that is what you are looking for. $\endgroup$ – sambler Oct 28 '17 at 3:40

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.