Need a way to program this.

XPutNameHereX

  • Posts: 19
I've thought of everything, but I just can't find a way to get part of my game to work.

Basically, there is an enemies killed counter. You'll see that it stays at 0. I need a way so that every time an enemy is pushed out the top, it goes up by 1. I've tried a lot of different things. (Note that I know how to make it go up by 1 every time, I just need a way so that it recognizes when it goes out.

Link: http://www.kongregate.com/games/Relaxzen1/everybody-edits-push-out?acomplete=push

Help!

magabriel4

  • Posts: 14
Try adding this to the scene :

If the enemy emoticon exits screen
- kill actor
- increment the enemies killed counter by 1

Or if that doesn't work :

1) Make a rectangular region somewhere in the top area where enemies are supposed to be killed; then
2) If enemy emoticon actor enters said region : kill actor, increment enemies killed counter by 1.

Hope I helped :D

Sift

  • Posts: 47
You can also put an invisible actor at that part of the screen, create a global attribute for the kill count, and put a behavior for the enemies that goes something like this:

When this collides with invisible actortype:
Set kill count to Kill count + 1
Kill self

XPutNameHereX

  • Posts: 19
I'll try that stuff, Sift. Magabriel, I've already tried both of those. Neither really work. I'll see if it has the right coding blocks for the Sift one.

coleislazy

  • *
  • Posts: 2607
If you just need to measure if they went off the top of the screen, its simple. Give the enemy actor a behavior:
Code: [Select]
if(y of self < (0 - height of self)) {
   enemies killed = enemies killed + 1;
   kill self;
}

If the "enemies killed" counter isn't a game attribute, you'll need to use the appropriate block to message the correct behavior. If your scene is larger than your camera and you just want to know when they go off-screen (not off-scene), instead of zero, use "y of camera".

EDIT: Make sure your enemies have used the block "make self always active" so they continue to process when off-screen.

XPutNameHereX

  • Posts: 19
If you just need to measure if they went off the top of the screen, its simple. Give the enemy actor a behavior:
Code: [Select]
if(y of self < (0 - height of self)) {
   enemies killed = enemies killed + 1;
   kill self;
}

If the "enemies killed" counter isn't a game attribute, you'll need to use the appropriate block to message the correct behavior. If your scene is larger than your camera and you just want to know when they go off-screen (not off-scene), instead of zero, use "y of camera".

EDIT: Make sure your enemies have used the block "make self always active" so they continue to process when off-screen.

I used your code:



But I get all of this:

Behavior: Design_1_1_EnemyMotion at line 41
Syntax error: expecting rightparen before of.
        if(y of self < (0 - height of self)) {

Behavior: Design_1_1_EnemyMotion at line 41
Syntax error: expecting identifier before rightparen.
        if(y of self < (0 - height of self)) {

Behavior: Design_1_1_EnemyMotion at line 41
Attribute is invalid.
        if(y of self < (0 - height of self)) {

Behavior: Design_1_1_EnemyMotion at line 42
Syntax error: expected a definition keyword (such as function) after attribute Enemies, not Killed.
   Enemies Killed = Enemies Killed + 1;

Behavior: Design_1_1_EnemyMotion at line 42
Syntax error: expecting rightbrace before semicolon.
   Enemies Killed = Enemies Killed + 1;

I've tried all the obvious stuff (doing exactly what it tells me to do) but it just keeps on giving me more and more errors.. Help the nub please!

Ryusui

  • Posts: 827
That's pseudocode. It won't work if you type it in as-is. Recreate the functionality using blocks, or use the proper values - "Actor.y", for example.
In the event of a firestorm, the salad bar will remain open.

XPutNameHereX

  • Posts: 19
SUCCESS! Mostly.

Managed, even after very epicly failing:



SO they now die. However, for some reason the counter still won't go up.


froz

  • Posts: 250
Check if you don't set enemies counter to 0 somewhere (f.e. in always event in any behaviour or in "when creating" event for behaviours of actors that are created during gameplay).



I also suggest that you change "create actor" to "create recycled actor" for enemies and "kill actor" to "recycle actor". It's made for cases like this one, when you create many identical actors, kill them and create more. It will make game use less resources (otherwise it may get laggy on slower PC with many enemy actors alive).

magabriel4

  • Posts: 14
Also, I believe that using increment Enemies Killed by 1 rather than set Enemies Killed to Enemies Killed+1 is a wee bit more efficient. It does exactly the same thing, it's just more efficient.

Well, your code there seems to be fine and perfect, so the thing that makes it wrong should be somewhere else, like, a part where the Enemies Killed attribute is reset to 0, like froz suggested.

Do you initialize the Enemies Killed attribute to 0 in a when created event?
Do you change Enemies Killed in any way anywhere else except in the When Created event and the event you posted here?

coleislazy

  • *
  • Posts: 2607
The "enemies killed" attribute you have is a local attribute (blue block), unique to that actor's behavior only. So, each actor has its own value. You need to either use a game attribute (purple block), which is universal to all actors/scenes/behaviors or have each actor message a scene behavior which controls the score. The article I linked in my previous post describes how to change an attribute in a different behavior.

XPutNameHereX

  • Posts: 19
The "enemies killed" attribute you have is a local attribute (blue block), unique to that actor's behavior only. So, each actor has its own value. You need to either use a game attribute (purple block), which is universal to all actors/scenes/behaviors or have each actor message a scene behavior which controls the score. The article I linked in my previous post describes how to change an attribute in a different behavior.

Thanks! I really appreciate your help! I shouldn't be coming back for a while!