General questions to the blender Game Engine

Hello,

I am developing a game and the game is getting pretty complex.
Most of the logic I try to solve with logic bricks and where the logic bricks fail I couple it with python.

Unfortunately, the game is getting so complex, that chaos is dominating more and more.

Here’s a picture of the logic of my main character:


And what you can see there is only one half of the whole logic.

Do you have any advice how to better organize the logic? Or are there any other ways to keep the complexity more simple?

The problem is that the logic is getting so complex that soon I won’t be able to connect a sensor with a controller of another object due to the distance they are laying apart.

Furthermore I have a question regarding blender itself.

The first time I open my game project the game runs smoothly with around 30 fps.
If I close blender and reopen the game, I only get 12 fps.
Is there something like a cache in blender which I can empty?

Everytime I close the game and want to run it smoothly again I have to restart my computer.
Did someone have the same problem?

Hopefully someone has solutions for this…

Thanks in advance

you are probably going to want to have a input object, that converts input to a list, and pipes it into your actor, and then evalute the list vs python or control states logic (turn list into string)

Everything is usually,

If pressing (list or sting) and current state is x:
    Do y

So your logic becomes

Actor on--------python

Or

Actor timer not zero---------python
Timer zero----and----Idle animation

And it sounds like you have found a memory leak?

If you want my honest opinion, I think that you’re overdoing it with logic bricks.

The screen I’m on right now isn’t big enough to make those bricks clear to me, but I’m pretty sure that you can do everything you’re trying to do there with only a few Python modules and 1/10th of those bricks. There’s not really much of a resource issue with what you’re doing (as far as I know, and let’s face it, I have zero idea how Blender’s resource management works), but that looks really messy and hard to maintain and work in. I think that you should focus on transferring some of your logic to Python.

That all these objects have to talk to each other directly speaks of bad design. Consider using messages to communicate between different objects,

Or yes, learning Python will definitely help - though it may just move the mess into code rather than logic bricks (and it’s harder to see mess in code)

Ehhh, sometimes objects have to link directly, for example a character object telling its model’s armature to change animations. Doing it exclusively, however, I agree is probably not great.

if 'armature' not in own:
    for child in own.children:
         if 'ArmatureTag' in child:
            own['armature']= child

Now you have the armature

own[‘armature’].playAction()

@BPR:
Posting random code is not helpfull.

@MichelleSea:
Great, then you link two objects. I consider an object and it’s skeleton to be a single entity.
But there is no need to have the so many objects all linked together as per the image at teh top

I was answering michele, this is the code to look up a armature that is the child of the physics hitbox, it works quite well for everything but blending idle.(not using a action armature)

@a-k-m
time to learn python, you should do all the complex logic with python while the brick sensors dictates when it is necessary to run the code, good luck

Each single object does not look like as it has a lot of bricks.

I suggest to use the filter toggles a the top of the logic brick window (above the bricks) to get a better picture.

I try to avoid inter-object connections as much as possible due to the chaotic look.

The main character has obviously quite a complex behavior. You can (and maybe already did) split the complex behavior into smaller isolated parts. Some of the processing can surely be moved to Python. Without more information I can’t advice details.

You can also use the build-in state machine to organize the logic. If you need more states a custom state machine in Python can help.

Thanks for the advices.
I will think about a solution to better organize it all.
Messages seems to be a good way to do it too.
But wasn’t the restriction of messages that they only transfer strings?

My game has two dynamic object which are connected via rigid body joint with each other (kite-game - kite and the player)
A lot of gameLogic is based on the angles, height and speed of both the kite and the player.

These variables are saved in properties to which many of the small objects have to have access to.
That’s what you r seeing in the picture.
E.g.: Basically it goes like this: if the property height of the player is 0 (ground contact) object x activates actuator.
If after getting airborne player gets ground contact again (collision) object y activates actuator.
If kite’s angle is 0-90°, object x activates actuator.

If I could save these properties to a global system and copy the properties from the two main objects to every other object, that could save a lot of mess.
Furthermore there are the keyboard inputs.

Sometimes I need to have one and the same keyboard input with true pulse on, with true pulse of and sometimes inverted.
At the moment there are 8 keys assigned.

I find it easier to see what’s going on using the logic bricks (There’s already quite a few scripts). But if you say that I really should consider moving it all to python, then that’s probably the way to go, in case there isn’t a solution for the situation I just described above…

@Monster: Usually I have the filter toggles on but then some sensors aren’t shown while I have the two concerning objects selected. Then I need to press “linked” to see the hidden sensors again. Btw, I just discovered your ressources and guides - awesome stuff, exactly what I need!

if you want to solve most of the action with logic bricks (like i prefer), put the lbs at the object they belong to. e.g. do not check the amount of ammo at your main char, check all shootings at the gun. if this doesnt work, because weapons are change often, you may also make invisible placeholders for gun, health, etc and make them child of your main char

Again, totally agreed. The magic of Python makes anything else so much more possible.

To be honest, that is just a normal day in my world, complex logic lol.
You just get used too it, but yeah python will help.

I find it easier to see what’s going on using the logic bricks (There’s already quite a few scripts). But if you say that I really should consider moving it all to python

Not all, logic bricks are just very easy to use, i would suggest combine those powers.
movement and properties transfers are best done with python.

for movements it just 1 brick connected to a script, if it is keyboard or always sensor it doesnt matter, thus saving you lots of bricks.
also with properties, you can make 1 script that is getting used by all (sub)parts of the main char to transfer it.

example:

from bge import logic

def get_player():


    scene   = logic.getCurrentScene()   
    player  = sene.objects['player']
    
    return player


def use_property():


    cont    = logic.getCurrentController()
    own     = cont.owner 
      
    player = get_player()
    
    if player['property_1'] == 10.0:
        #do something 
        #set speed
        own.localLinearVelocity = [0.0, 1.0, 0.0]
        
    elif player['property_2'] == True:
        #do something
        #set owners property
        own['property'] = 1

And you connect the (sub)parts to use_property as module, so scriptname.use_property
Reminder, this is a simple example and untested but should work.

of course you need to adjust it to youre own needs.