Hey guys, I’ve started my trek into learning more advanced stuff like menus, and exceptions, but I need help. I’ll post a few codes and explain what I don’t understand.
# This handles the gates
import GameLogic
me = GameLogic.getCurrentController().getOwner()
cont = GameLogic.getCurrentController()
init = cont.getSensor("Init")
nr = cont.getSensor("Nr")
through = cont.getSensor("Through")
gate = cont.getActuator("GateMess")
# the (random number) of gates are registering themselves into a global variable
# be shure to name the gates Gate.000...Gate.XXX in the correct order!
if init.isPositive():
# set the visible gate name
nr.getOwner().Text = me.name[2:]
try:
GameLogic.gates[me.name]=me
except:
# first gate?
GameLogic.gates={}
GameLogic.gates[me.name]=me
# ship has passed the gate, send message to the ship
if through.isPositive():
gate.setBody(me.name)
GameLogic.addActiveActuator(gate,1)
This was used in subracer, the game on the BGE kit. the part I’m not getting is this…
if init.isPositive():
# set the visible gate name
nr.getOwner().Text = me.name[2:]
try:
GameLogic.gates[me.name]=me
except:
# first gate?
GameLogic.gates={}
GameLogic.gates[me.name]=me
I do understand that nr.getOwner().Text=me.name[2:]
it’s basically setting the gate name without OB in it, but after that it just losses me. I’ve barely been about to find resources on try: and except: so I dont’ know very much on how it works…
GameLogic.gates[me.name]=me this completely makes me lost in what it does, and there is not anything in the scene, being object, material, properties or logic bricks with the name ‘gates’…
GameLogic.gates={} What are the {} brackets being used for or are in reference to what? I want to assume to clear GameLogic.gates, but I have no clue…