Alice Community

Alice Community (
-   How do I...? (
-   -   Any way to "disable" methods? (

Deidara1BG 07-20-2011 06:11 PM

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*


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...

sfunk 07-20-2011 06:32 PM

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

Nighthawk0973 07-20-2011 08:09 PM

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)
If EnemyAlive == true {
This will test if the boolean variable we created is equal to true.
Set EnemyAlive == False
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.

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:
If EnemyAlive == True{
//Enemy Die and Disable AI
Set EnemyAlive = False


That's the complicated version of simple! Hope you enjoyed!

Deidara1BG 07-21-2011 08:15 AM

Oh,i see.Thanks,now it is more clear to me.Gonna try it,thanks!

7yrold4Alice 08-08-2011 05:27 PM

I had that problem too!

puzzlemenow 05-21-2012 03:55 PM

can u make a video tutorial on this?

if so thanks alot

All times are GMT -5. The time now is 09:08 AM.

Copyright ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.