x


Can I use multiple If/else in 1 function?

I am trying to create a trigger that has 4 different things that can happen based on the state in which the trigger is in. Can this be done with If, else, else, else? or is there a better way to do it?

Answer - self found.. yes but needs to be else if for each else except the last.. example..

function Whatever(){
if(whatever){
something happens;
}
}
else if(whatever){
something else happens;
}
else(whatever){
last thing happens;
}

Answer found at http://www.w3schools.com

more ▼

asked Sep 11 '11 at 07:48 AM

Ajaxx84 gravatar image

Ajaxx84
35 8 11 13

Have solved question myself.

Sep 11 '11 at 04:56 PM Ajaxx84
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Answered in original post..

more ▼

answered Sep 11 '11 at 04:56 PM

Ajaxx84 gravatar image

Ajaxx84
35 8 11 13

+1 for proper use of UnityAnswers :) (it's just so refreshing if a new user cleans up all by himself once in a while... ^^' ) Greetz, Ky.

Sep 11 '11 at 11:04 PM SisterKy
(comments are locked)
10|3000 characters needed characters left

I believe using if or else is enough. ^^

more ▼

answered Sep 11 '11 at 08:01 AM

henry96 gravatar image

henry96
597 16 20 23

(comments are locked)
10|3000 characters needed characters left

For something like that I would use a switch statement.

switch(trigger){
    case(a): whatever;
    break;

    case(b): whatever;
    break;

    case(c): whatever;
    break;

    case(d): whatever;
    break;

    default: whatever;
}
more ▼

answered Sep 11 '11 at 05:21 PM

Piflik gravatar image

Piflik
5.4k 15 26 44

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x982
x146
x16

asked: Sep 11 '11 at 07:48 AM

Seen: 1140 times

Last Updated: Sep 11 '11 at 11:04 PM