Hi everyone, i have a few questions about the latest GE pyapi.
firstly, what is the alternative to “GameLogic.”, as in the variables you assign to GameLogic, such as GameLogic.coolthing as apposed to GameLogic.getCurrentController()
Thanks!
That’s why! thanks!
can i use that method if i am assigning a variable:
var = bge.owner["named"][0]
or
var = bge.(owner["named"][0])
or
var = bge.str(owner["named"][0])
or would i have to use
named = owner["named"][0]
var = bge.named
note the reason i am using a variable is that it uses the value of a property of the owner as a known created variable;
for showing & deleting enemies on map.
Global vars shouldn’t be stored on the bge or GameLogic modules as attributes as I believe those modules are reinstated on game changes, instead you should use the globalDict atrribute (which is a dictionary object) of bge.logic and GameLogic, e.g:
would i be right in thinking this would remain as a value, even after using the set scene actuator?
But the main question i have is how to name a globalDict variable with a variable, read the comments:
import bge
controller = bge.logic.getCurrentController()
#nameofowner gets the name of the owner object, uses that as a variable,
#e.g if the <b><i>owner was called 'boat'</i></b>, in 2.49b it would be: <b><i>GameLogic.globalDict['boat']</i></b>
#but i want <b><i>to set and get it using</i></b> a<b><i> python</i></b> variable: '<b><i>controller.owner</i></b>';
#should i use '<b><i>bge.logic.globalDict[str(controller.owner)]</i></b>' or '<b><i>bge.logic.globalDict[controller.owner]</i></b>' ??
nameofowner = controller.owner
attribute = bge.logic.globalDict[nameofowner]
i know, but can i get the GlobalDict to read it as a string, not a python variable if i don’t use quote marks?
import bge
controller = bge.logic.getCurrentController()
nameofowner = controller.owner.name
attribute = bge.logic.globalDict[nameofowner]
##############
#without ('') marks, will it be read as a string value of the python script?