Any way to "disable" methods?
Hello community!
In my FPS,you click the enemys to kill them.Is there any way i can make something like this? While the mouse is clicked on *enemy*, stop/disable *method* OR While the mouse is clicked on *enemy*,do *method* (in the *method* in the second example there would be either a falling or a dissapearing animation,and then the "disable" thing (if its even possible!). In other words,my question is is there a way to stop a method while in game,or using another method.If it was for an animation it would be way easier,but i cant predict when the player will shoot the enemy,or if the player will even shoot it... |
Use a boolean variable, have it set as true when the world starts and use an IF/else statement saying if that is true it will run that method, but once the character clicks the object/enemy, have that variable turn to false to stop the method
|
If your clueless on what he just said than do this:
(For the sake of this mini-tutorial, lets pretend we're creating an enemy death method, and making it so that the method can only be called once) First create a new variable by visiting the world properties tab and clicking 'Create new Variable'. Set it's type to boolean (True/False) and it's name to EnemyAlive, make it's value set to 'True'. Now in the methods tab create a new method and name it 'EnemyDeath' now your code for the method should be set to the following. (sorry if this looks more like Java than alice, that's because I'm using pure text) [CODE] If EnemyAlive == true { [/CODE] This will test if the boolean variable we created is equal to true. [CODE] //EnemyDeathCodeGoesHere Set EnemyAlive == False [/CODE] What we're doing here is initiating the enemy death code, disabiling his AI, and making him perform a death animation. Next we set the value of EnemyAlive to false, so that this method cannot be repeated more than once. [CODE] }Else{ } [/CODE] Now we finish things off by closing the If and opening the 'Else', as you can see, there is no code in the Else, so we simply close the else. That's all of the method! What this does in a quick runthrough is simply. We have a variable that states our enemy is alive. Once he is shot we call on a method that makes him die. Inside this method we test a condition: if the EnemyAlive variable is true, than kill the enemy and set this variable to false, and then end the method. When we shoot the enemy again, it does the same method again but this time, since we set 'EnemyAlive' to false it skips the 'If' part (therefore not repeating the death animation) and begin the 'Else' part, which does nothing and than simply ends the method. This is our methods code all in one: [CODE] If EnemyAlive == True{ //Enemy Die and Disable AI Set EnemyAlive = False }Else{ } [/CODE] That's the complicated version of simple! Hope you enjoyed! |
Oh,i see.Thanks,now it is more clear to me.Gonna try it,thanks!
|
I had that problem too!
|
can u make a video tutorial on this?
if so thanks alot |
All times are GMT -5. The time now is 03:31 AM. |
Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.