throw following code block is to ‘throw’ an item from one actor object to a target object stored in the list target.
the thrown object gets .addObject’d and then stored in string type game prop in a one-time run function outside and before the following code block is run.
Please look in the code block for the line of #'s to see the comment and my problem. See if you can solve or rewrite the idea
The other rules: can’t store the item in the global dict and cant retrieve the item with list comprehension or a for loop
gd = logic.globalDict
actor = battle_functions.get_actor_obj() <- a kx game object
target = gd[actor['battleID']+'_target'] < - a list of kxgame objects
thrown = actor['thrown_item'] < a kx game object inside of a string type game prop
try:
logic.getSceneList()[0].objects['CameraParent'].alignAxisToVect(Vector(logic.getSceneList()[0].objects['CameraParent'].getVectTo(thrown)[1]),1) # look at the camera
if actor.children[0].getActionFrame(2) == actor.children[0].actuators['Throw'].frameEnd:
thrown.removeParent() # take from parent in order to apply velocity on the correct frame
vect_to_target = thrown.getVectTo(target[0])[1]
thrown.alignAxisToVect(vect_to_target,1) # align to the target kx game object
thrown.setLinearVelocity(vect_to_target*48,1) # set velocity towards it
actor.children[0].stopAction(2) # stop throw animation
distance = thrown.getDistanceTo(target[0])
print(distance)
if distance < 10: # if its close enough to the target kx game object
thrown.endObject() ###### THIS is where the problem occurs because the game prop is converted back to string type once the KX game object that was stored in it disappears
except:
# this stuff is for functions that are called afterward, but i only thought to put them in an exception
if logic.getSceneList()[0].objects['DefaultCamera']['action_timer'] > logic.getSceneList()[0].objects['DefaultCamera']['action_time'] -1:
logic.getSceneList()[0].objects[str(actor)+'WM'].setVisible(True)
logic.getSceneList()[1].objects['CameraHUD']['throw_item'] = False
logic.getSceneList()[0].objects['DefaultCamera'].timeOffset = 40.0
return True