I am making a project with enemies that give experience when they die. The problem is that I need the forever script so that it will work more than once but then it keeps repeating the part where it gives me exp. As a script I tried:
When green flag clicked
Forever if [enemy hp] = 0 or [enemy hp] < 0
broadcast "enemy dead"
When I receive "enemy dead"
change exp by 5
How do I make the script always work after the green flag is clicked, but only happen once?
Offline
i think its like this:
<when green flag clicked>
<forever>
<if> <( <{ ememy HP }> <<> 1 )>
<change{ exp }by( 5
the difference between mine and yours is you used the <forever if>
block and i used
<forever>
<if>
Last edited by funkymonkey (2008-01-06 19:34:10)
Offline
funkymonkey, all that your change does is to make the script slower, it does not change the meaning.
There are two solutions, depending on whether the enemy hit points ever go back up.
If not, then you can do
when greenflag clicked
wait until enemy HP < 1
change exp by 5
If the hitpoints can go back up, then you can do
when greenflag clicked
forever
wait until enemy HP < 1
change exp by 5
wait until enemy HP > 0
Offline
kevin_karplus wrote:
when greenflag clicked
wait until enemy HP < 1
change exp by 5
but then it only does it once, so whats the point? there are most likley going to be more ememies than just one
Offline
B-Reyn,
The issue with your script is that once the enemy is dead (its HP variable is < 0), your forever loop will keep piling on "experience" by broadcasting "enemy dead". From the information that you've given, Kevin's solution looks like a very nice way to handle the problem.
If there are multiple enemies active at the same time, a broadcast is one way the enemies could notify the "Hero" that he/she made a kill. In this case, each enemy could have its actions driven by a forever loop, and could keep track of their own health. When an enemy's health gets to less than 1, it would broadcast "EnemyKilled", then stop its script (so that the broadcast only gets sent once).
When I receive "AnimateEnemy1"
Go to (start x and Y)
Show
Forever
(Do mean things that enemies do)
If MyHealth < 1
Hide
Broadcast "EnemyKilled"
Stop Script
Another way to do the same thing would be to make the Hero's experience a variable "for all sprites". Then, instead of having the enemy broadcast to the Hero, the enemy could just add to the experience variable when it "dies".
Funky,
The second script that Kevin proposed will address having another enemy, once the enemy is alive again (HP > 0) the script will go back to waiting for the next "kill".
Offline