Page 1 of 1

Variable+Animation changing

PostPosted: Fri Oct 06, 2006 12:21 pm
by Troodon
Hi everybody! Hi all my game editor forum friends!
It has been long time since I was active in this forum but I'm still in top writers list.
(Position 12th used to be 9th)

What's the best way to make this:
if variable kunto = 3 change animation to config2
if variable kunto = 2 change animation to config3
if variable kunto = 1 change animation to config4
if variable kunto = <0 destroya actor

Thanks!
(as you can see I've forgot little game editor)

PostPosted: Sat Oct 07, 2006 6:33 am
by DilloDude
Code: Select all
switch (kunto)
{
    case 0:
    DestroyActor("Event Actor");
    break;

    case 1:
    ChangeAnimation("Event Actor", "config4", FORWARD);
    break;

    case 2:
    ChangeAnimation("Event Actor", "config3", FORWARD);
    break;

    case 3:
    ChangeAnimation("Event Actor", "config2", FORWARD);
    break;
}

PostPosted: Sat Oct 07, 2006 11:22 am
by Troodon
Thanks! And that's working in the 1.3.3 (2005) version too?
EDIT: It's working! Sorry for distracting you but what if I want to destroy the actor when kunto is <1. Because in my game the kunto can change so fast that the actor doesn't get destroyed if it goes below zero. :wink:

PostPosted: Sat Oct 07, 2006 9:52 pm
by DilloDude
just have your case 1, case 2, case 3, and then put default: DestroyActor... instead of in case 0. This will also make it destroy if it is greater than 3, though, unless you test it with an if.

PostPosted: Sun Oct 08, 2006 7:24 am
by Troodon
DilloDude wrote:just have your case 1, case 2, case 3, and then put default: DestroyActor... instead of in case 0. This will also make it destroy if it is greater than 3, though, unless you test it with an if.

I know this is sounding very stupid but :oops: :oops: how do I made it default. If I make the destroy actor before switching, the actor will be always destroyed. So do I make like this?

Code: Select all
switch (kunto)
{
    default:
    DestroyActor("Event Actor");
    break;

    case 1:
    ChangeAnimation("Event Actor", "config4", FORWARD);
    break;

    case 2:
    ChangeAnimation("Event Actor", "config3", FORWARD);
    break;

    case 3:
    ChangeAnimation("Event Actor", "config2", FORWARD);
    break;
}
:oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops:

PostPosted: Sun Oct 08, 2006 10:16 am
by DilloDude
Yes, only you will need to put the default after the other cases:
Code: Select all
switch...
{
case 0...
case 1...
case 2...
default...
}

this will do the script in the appropriate case if it is 0, 1, or 2, and if not, it will do the script in the default.
Also useful with switch statements, if you don't enter break at the end, it will keep going down the list of code and executing functions anyway. There are cases where you do want this to happen, but often you don't.
It may be best to think of it as one block of code, you check a variable and enter in at the appropriate entry point, and keep going till you come to a break.