Can AI be cleared by using the bricks after a task has been completed?


(Cotaks) #42

script name = checkenemies.py
python module -> checkenemies.check_for_win_conditions

but i adjusted your blend it works now have fun with it

Player is player and enemy is enemy, a property is all that is needed?

no your player is called FP not player :wink:

The left spider is how you build it, so kill that one and win, let spiders kill you and lose


(dtrip) #43

Another walkaround would be to

The AI’s send “There is an AI alive” message to the player all the time (use Always->Skip to skip a few frames, no need to do it every frame).

Now, the player has a property “Everyone dead” , that he increments automatically every frame
(or every other frames, with Skip as well).

But every time he receives “There is an AI alive” from AI, he makes “Everone dead” back to zero.

Now, when all AI are dead, he will stop zeroing “Everyone dead”, so it will eventually become
larger than, say, 10.

So if “Everyone dead” becomes sufficiently large, it should mean that there are no AI’s left
to send the “There is an AI alive” message.

This is how I would do it. The downside is that once they are all dead, it takes some time for
the player to realize that. But that is not necessarily bad, as the game might go on for a couple
seconds and then change scene to Victory! or whatever needs be done.

PS: To clear the AI after a task has been completed, you can do something similar with the
player sending a message to everyone and the AI’s have a counter. When they stop receiving
the message and the counter goes over a value, they endObject() themselves. I suppose it is
possible for the player to send a message to everyone (I do not know for a fact), so it should be
feasible.


(modelinblender) #44

Hmm, for the moment this code does the task fine. Its all new to me. Thanks.


(Cotaks) #45

It’s a good workaround but not very efficient. so from now on, use the code i wrote a post of me higher and use that. 1 always 1 python all you need to check for win or lose situation. You can still add a delay of how many tics you like, to not let it popup instantly.

Now you can also see how easy python actually is compared to the logic bricks.


(dtrip) #46

Cotaks,

you are right of course. I meant “this is how I would do it, if need only bricks”, because the OP said with bricks only. But python is the only way to finish the game without compromises.