Jump to content

Sign in to follow this  
Lucky44

Weird error when using exitWith

Recommended Posts

EDIT: the problem had to do with the boolean use of "quitNow"...I should not have been using quotation marks around TRUE and FALSE. I figured this out when I changed it to a simple 1/0 variable, it works. I've changed it below to work as well.

This shooting range script was going along nicely. I have 12 pop-up targets at various ranges (40m-300m) that pop up in a psuedo-random order for 5 seconds, score a point if hit, etc.

But then I wanted to add a way to kick it out of a trial if the player wanted to end early.

So in the trigger that calls the rifle range script to activate, I put a deactivate action: simply make a variable called "quitNow" = "true" if the player leaves the trigger area.

But I'm getting an error soon after the script starts (after being fired from the trigger area). It's saying that I'm missing a ")" on the line with

"if (quitNow="true") exitwith {[nil,nil,rHINT,"Shooter left the box. Ending the trial early."] call RE};"

I've been banging my head on the keyboard for an hour on this. I'm probably missing something simple. Any suggestions?

if (!isServer) exitWith {}; // only run this on the host computer


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////INITIALIZATIONS //////////////////////////////////////////////////////////////////////////

// Create the array of targets//////////////////////////////////////////////////////////
_TarArray = [tar1, tar2, tar3, tar4, tar5, tar6, tar7, tar8, tar9, tar10, tar11, tar12];
TarArray = _TarArray;

// Create an array of target choices, in sequence, to be used for the 40 targets in a row, in psuedo-random order
_TarSeq = [tar4, tar7, tar1, tar5, tar10, tar8, tar2, tar12, tar4, tar9, tar11, tar3, tar6, tar7, tar3, tar9, tar2, tar11, tar5, tar8, tar6, tar8, tar12, tar10, tar5, tar9, tar6, tar3, tar7, tar10, tar4, tar9, tar5, tar8, tar4, tar10, tar6, tar3, tar7];
TarSeq = _TarSeq;

// Force targets to stay down when hit:
nopop = true; // this applies to all targets, automatically

// Set all targets to DOWN position to start; 
{_x animate ["terc", 1] } forEach _TarArray;


//Initialize Variables
TargetScore = 0; // counts hits on targets
_targetCounter = 0; // counts targets that have popped up
quitNow = "false"; // this is the check to see if the player left the shooter's box

[nil,nil,rHint, "The marksmanship trial will begin in 10 seconds."] call RE; // the rHINT with RE (Remote Execution) runs on all clients
sleep 10;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////The Trial Loop //////////////////////////////////////////////////////////////////////////

// Loop 40 times, while counter = 0-39
while {_targetCounter <40} do {

// Choose the target to pop up from the sequence.////////////////////
(_TarSeq select _targetCounter) animate ["terc", 0]; // from the array _TarSeq, SELECT the _targetCounter-th target and pop it up

// Put eventHandlers on each target for event "hit"/////////////////////////////////////
(_TarSeq select _targetCounter) addEventHandler ["hit", {_this execVM "tar_hit.sqf"}];


// if the shooter leaves the "box" between the cones, end the trial early.
	if (quitNow=true) exitwith {[nil,nil,rHINT,"Shooter left the box. Ending the trial early."] call RE};


sleep 5; // hold the target up for 5 seconds (or until hit)
(_TarSeq select _targetCounter) animate ["terc", 1]; // PUT DOWN the target if not already down

_targetCounter = _targetCounter +1; // keep count of how many targets have been popped up


_pause1 =(random 2)+3; //  pause between targets for 3-5 seconds
sleep _pause1;

};// End of trial loop

titleText ["The trial is now over.","PLAIN"]; // goes only to host? That's OK, really, since as long as one person gets this, it helps
sleep3;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////CONCLUDING ACTIONS //////////////////////////////////////////////////////////////////////////

// Remove eventHandlers on each target for event "hit"/////////////////////////////////////
{_x removeAllEventHandlers "hit"} forEach _TarArray;
nopop = false ; // let them pop up if shooter wants to just practice casually
{_x animate ["terc", 0] } forEach _TarArray; // Put up the targets if not already up



FinalScore = parseText format["<t font='LucidaConsoleB' color='#ff0000'>Your fianl score = %1.</t>",TargetScore];
[nil,nil,rHINT,FinalScore] call RE;
sleep 4;
//hint format ["The Score = %1.  \n0-23 hits=More Practice \n24-29 hits=Marksmen\n30-35 hits=Sharpshooter\n36+ hits= Weapons Expert",TargetScore];
TargetScore = 0; // reset for another try, possibly

and here's the script that fires if the target is hit, called "tar_hit.sqf"

// This simply counts hits and keeps score/////////////////////////////////////////

TargetScore = TargetScore +1;
publicVariable "TargetScore"; // maybe making this a PV will let it be broadcast???

goodhit = "yes"; // flags the on-map trigger to send the hit messages to all...hopefully

// after a hit is scored, remove the EventHandlers to prevent multiple hits per pop-up
{_x removeAllEventHandlers "hit"} forEach TarArray;

Edited by Lucky44

Share this post


Link to post
Share on other sites

you don't need the =="true"... true is boolean and not text!

Use this instead :-

if (quitNow) then {...
};

Share this post


Link to post
Share on other sites

No, actually i0n0s is correct given that he uses "quitNow" = "true" (should be quitNow = "true" btw), and i0n0s correctly indicates use of double equal (== / equal to) versus the single equal (= / assignment).

But yeah, it would be better using it as a boolean rather than a string, like:

quitNow = true;

if (quitNow) then { ...code... };

Edited (but untested) version in spoiler:

  Reveal hidden contents
Edited by CarlGustaffa

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  

×