Jump to content
Sign in to follow this  
beta

Else if logic problem

Recommended Posts

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (isServer) then

{ //server

[] execVM "scripts\main_thread_server.sqf";

if (!(isNull player)) then

{ //server-client

[] execVM "scripts\main_thread_client.sqf";

}

}

else

{ //client

if (isNull player) then

{ //JIP-client

[] spawn { waitUntil { !(isNull player) };

[] execVM "scripts\main_thread_client.sqf";

}

[] execVM "scripts\main_thread_client.sqf";

};

I have this code running in the init.sqf.

Gives me an error, missing a "}" after the { under the else.

Not sure what is wrong here ...

Any ideas?

Edit: And yes, I just noticed that if the player is a JIP-client, the main_thread_client.sqf will be execVM'd twice crazy_o.gif

Share this post


Link to post
Share on other sites

try to add a ; after the closed bracket of the IF THEN part:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">else

{ //client

if (isNull player) then

{ //JIP-client

[] spawn { waitUntil { !(isNull player) };

[] execVM "scripts\main_thread_client.sqf";

};

[] execVM "scripts\main_thread_client.sqf";

};

OH! WAIT!

When you execute the first IF, I see that you use a THEN, but after that you close all the brackets...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (isServer) then

{ //server

[] execVM "scripts\main_thread_server.sqf";

if (!(isNull player)) then

{ //server-client

[] execVM "scripts\main_thread_client.sqf";

}

}

else

try to take out the last closed } so to obtain:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (isServer) then

{ //server

[] execVM "scripts\main_thread_server.sqf";

if (!(isNull player)) then

{ //server-client

[] execVM "scripts\main_thread_client.sqf";

}

else

{

//client

if (isNull player) then

{ //JIP-client

[] spawn { waitUntil { !(isNull player) };

[] execVM "scripts\main_thread_client.sqf";

}

[] execVM "scripts\main_thread_client.sqf";

};

};

Share this post


Link to post
Share on other sites
Quote[/b] ]try to add a ; after the closed bracket of the IF THEN part:

Trying this, I get an error: missing ";" after the opening "{" of the else.

Quote[/b] ]try to take out the last closed } so to obtain:

Trying this, I get an error: missing "}" after the opening "{" of the first if.

I've read over the biki page on if then else, from what I read there, this should be working ...

http://community.bistudio.com/wiki....tements

It's probably something incredible stupid .... usually is smile_o.gif

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (isServer) then {

 //server

 [] execVM "scripts\main_thread_server.sqf";

 if (!(isNull player)) then {

   //server-client

   [] execVM "scripts\main_thread_client.sqf";

 };

} else {

 //client

 if (isNull player) then {

   //JIP-client

   [] spawn { waitUntil { !(isNull player) };};

 };

 [] execVM "scripts\main_thread_client.sqf";

};

might or might not work

Edit: several formating issues

Share this post


Link to post
Share on other sites

Okay. Figured it out. As predicted, quite stupid mistake.

The if then else works right.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (isServer) then

{ //server

[] execVM "scripts\main_thread_server.sqf";

if (!(isNull player)) then

{ //server-client

[] execVM "scripts\main_thread_client.sqf";

};

}

else

{ //client

if (isNull player) exitWith

{ //JIP-client

[] spawn { waitUntil { !(isNull player) }; };

[] execVM "scripts\main_thread_client.sqf";

};

[] execVM "scripts\main_thread_client.sqf";

};

Is the code that works.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[] spawn { waitUntil { !(isNull player) }; };

This was the line with the error, I was missing the spawn's closing bracket.

I guess it's time to enable my IDE's "auto-close bracket" feature icon_rolleyes.gif

Thanks for the help Linker Split!

Share this post


Link to post
Share on other sites

Sorry for necromancing this thread.

I want todo this:(java style)

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if(rofl){

    //Do something.

}else if(!rofl){

    //Do something else.

}else{

    //Above failed, do this.

}

I have tried with various "sqf" syntaxes, but I can't get it to work without failing with "expected code blablablah"

like

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if(rofl) then {

    //Do something.

}else if (!rofl) then {

    //Do something else.

}else{

    //Above failed, do this.

};

This doesn't work.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if(rofl) then {

    //Do something.

}else{

    if (!rofl) then {

         //Do something else.

    };

}else{

    //Above failed, do this.

};

Doesn't work either.

In short.

I want to check two values, if none of them is true, I want to do something else.

a "switch do" thingy wouldn't work in this case as the check value isn't a predefined variable

Any assistance would be appreciated.

Thanks in advance!

Share this post


Link to post
Share on other sites

Your abstract example doesn't make much sense...

"rofl" can either be true or false, but there wouldn't be a third alternative. (But I assume that that's just a matter of picking a bad example.)

If I go by your description of the problem ("I want to check two values, if none of them is true, I want to do something else."), I would suggest something like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if ((a==1) && (b==2)) then {

  // do something

} else {

 // do something else

};

Share this post


Link to post
Share on other sites

Sorry for not posting the best example.

Thanks for answering.

So basically an:

if

else if

else

as the "java example" above doesn't work?

I can not find the .sqf file where I started to code this banghead.gif

But I'm pretty certain I wanted something which required the if-else if, else statment.

Nevermind I'll work around that, adopting it to ArmA scripting. smile_o.gif

Offtopic:

For the ones it might concern, "I'm back!"

I was getting tired of all games I was playing, I got stuck in the MMO-swamp.

And a while back I thought "Hey, what about looking into the games you played before? like ArmA.

I found out about the "Warfare" mod and read the patch notes for 1.14 and I was pleased.

I persuaded my friends to buy ArmA and Queens Gambit.

Yet to determine if the AI vs night missions has been fixed tho' something which I'm testing now.

I like night missions but did not approve on the 1.05-1.08:ish "accuracy" where the AI found me at night.

Share this post


Link to post
Share on other sites

Try this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if(rofl) then

{

//Do something.

}

else

{

if (!rofl) then

{

//Do something else.

}

else

{

//Above failed, do this.

};

};

Share this post


Link to post
Share on other sites

You have to nest the "if" statement from the "else if" (OOP-style).  In a lot of Object-oriented Programming languages, "else if" is used instead of an "else" followed by a nested "if" but that's not the case here (presumably) because scripting != programming.

So write it like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (expression) then

{

 ...statements...;

}               // note the lack of semicolon

else

{

 if (expression) then

 {

   ...statements...;

 }             // note the lack of semicolon

 else (expression) then

 {

   if (expression) then

   {

     ...statements...;

   }           // note the lack of semicolon

 }

};              // note the semicolon

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×