beta 0 Posted February 8, 2008 <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 Share this post Link to post Share on other sites
Linker Split 0 Posted February 8, 2008 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
beta 0 Posted February 8, 2008 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 Share this post Link to post Share on other sites
Rastavovich 0 Posted February 8, 2008 <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
beta 0 Posted February 8, 2008 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 Thanks for the help Linker Split! Share this post Link to post Share on other sites
Taurus 20 Posted October 27, 2008 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
kronzky 5 Posted October 27, 2008 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
Taurus 20 Posted October 27, 2008 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 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. 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
snkman 351 Posted October 28, 2008 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
Namikaze 0 Posted October 28, 2008 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