Jump to content

if else statements in behaved


Recommended Posts

I am looking at Behaved since a long time (hell, i opened GTK Radiant last night for the first time in close to 2 years) and I am wondering what the limitations of Behaved are. Myself, I am a frontend-developer by proffession and know my way in scripting languages as JavaScript and PHP. So Behaved shouldnt be that much of a challenge, but looking at it and having in my mind a few ideas, I am wondering where the limit is.

 

For instance, the idea in my mind is that my puzzle has to be done over 5 switches I want to activate in a certain order, but the idea is that the sequence can randomize between 2 different combinations. All other combinations should trigger a bad responds in game (such as a wave of stormies), however, if combination 1 is active, it should do the right thing, whie combination should also trigger the bad responds, and vice versa if combination 2 is the right one, depending on a generated number in the spawn script as a global.

 

In PHP, which i work the most with, we can either define a case or an else if, but Behaved doesnt have such a thing. Is it possible to just add if statements, and later on add an else? Or do i have to add specificly an else after the first if?

Link to comment

"else if" is really just syntactic sugar in C-like languages for:

if(...) {
} else {
    if(...) {
    }
}
This happens since the {} are optional when you're dealing with one statement. Since the else block contains only one statement (an if), the braces around the else block are optional, thus producing "else if".

 

You can program without using switches if you use else-if ;)

Link to comment

I know what you mean there, but i didnt know how behaved would respond to it. I thought first to make it as multiple if's, but then i would mess up the checks, cause it would automaticly kick of the else statement. But in this case i try to make it check for another value. Anyway, i tried to make a schematic like this.

variable x = z
if(x === y) 
    {shut down power} 
else
    { if (x === z)
        {shut down power}
       else 
        {wave of stormies}
    }

         
    

So i only have to use one time the else, right, if i read it correct, cause the else after the second if would be the regular else statement if all fails? This would be in normal programming syntax, just dont wanna mess it up, and stare for ages at a script :)

 

btw, i see if i do an if, i can only use one parameter to check, is it possible to do an and and make it check for multiple parameters? Or do i have to do if in if's?

 

Anyway, i made a picture of what I think is the right procedure, can somebody verify?

 

behaved.png

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...