def get_scene(scene_name):
scenes = logic.getSceneList()
scene = None
for sce in scenes:
if sce.name == scene_name:
scene = sce
if scene == None:
print('\n*** No scene found with the name: ' + str(scene_name) + ' ***\n')
else:
return scene
Hello,
I’m not a programmer, but what specifically is going on here?
Is it a scene 1 or 2 function setup? So one screen loads after a result and another one loads after an alternative result.
Then it creates an anchor named scenes to store something that the logic object (unmentioned in your code) returns when `.getSceneList()` is called on it. (it’s probably a list, but who knows)
Then, an empty variable is created, named “scene”.
The rest of the code is a simple loop over all enumerable entities in the scenes, check the entity name property is the same as the scene_name parameter, assigning that entity to the empty variable scene if it matches.
(if a second or third entity matches the name, then the scene variable will end up pointing just to the last match)
In the end, if scene is still empty (no matches in name), it prints something and returns nothing. If scene is not empty, then it will return the scene.
Now, what the logic object is, and what the .getSceneList() function returns, it’s out of scope here. There’s so much that can be hidden behind a single function call…
It iterates over some iteratable component of the given object and if any of it is negative it is telling you so. If one “needs” this is something else..
The other one is “a shortcut” to get some object from a specific scene. ( Which might lead to some error when the scene named scene_name does not exist and/or return some “undefined” object.. ins some languages often a null pointer or some nul pointer exception or in python.. (What was it ?) null, none ?? )
As for everything else but especially for computer languages or code snippets: context is king
def bullet_action(cont):
own = cont.owner
if not allPositive:
return
own.applyMovement([0,distance,-bullet_drop], 1)
y_vec = own.worldOrientation.copy().col[1]
y_vec.magnitude = distance
end_vec = own.worldPosition.copy() + y_vec
ray = own.rayCast(end_vec, own.worldPosition.copy(), 0)
if ray[0]:
if 'health' in ray[0]:
ray[0]['health'] -= damage
if ray[0]['health'] <= 0:
if 'enemy' in ray[0]:
player = own.scene.objects['Hitbox_FPS']
player['score_count'] += 1
The code is set with a few functions, and the main one being a bullet, the whole code does everything, so whether the AI has 0% and loads a success scene, the code is by all of this.
I assumed the above was all to do with that, and based off a positive Ray Hit or some crap like that. And what ever else.
ray = own.rayCast(end_vec, own.worldPosition.copy(), 0)
if ray[0]:
All to do with a Ray and positive, so one leads to a win or lose, depending on the def health counter function.
In fact i have problems to understand what you are asking here.. this may be because i’m not a native english speaker or you are IDK.
It seems when you say you are not a programmer but you want to understand this code, whereever this comes from, you may “simply” study the programming language and also th eblender API a bit more.
Even as a programmer usually it’s not enougth to look at some small piece of code.
The bullet casts a ray to the scene, in the direction that it’s travelling.
If the ray hits an object (“if ray[0]”), and if that object has a “health” property (“if ‘health’ in ray[0]”), then subtract the damage power of the bullet from the object’s health (“ray[0][‘health’] -= damage”).
Finally, it checks if the object is the “enemy” and if there’s any health left in the object.
If health is now 0 or negative, change the player’s object to “Hitbox_FPS” and increment the “score_count”.
This is running for each frame, so if there’s no hit, the process repeats itself in the next frame, moving the bullet some more along its path.
I’ll try to read all your code tomorrow as I’m a bit tired now, but you should grab a paper and a pencil and write down the functions for each object, and how they interact with each other, to make a map/graph of what’s going on.
I’m not fully following the logic here… Thought my knowledge of BGE is not that deep, I don’t think you’re in the right path either.
I advise you to read the BGE documentation, or even better, take a look to the UPBGE documentation. And of course, learn a bit of Python, which isn’t that difficult.
This is probably more difficult than you think.
IIRC you’d need to do this in parallel threads, and I don’t know if BGE even allows it *. But it’s not a light solution and for sure not for someone unfamiliar to programming.
* Edit: I’ve found this commit from 14 years ago, and they added an async parameter to LibLoad, which should load a scene in a new thread and keep the main thread from freezing.