I'm having some trouble with a script; I'm attempting to set up a never-ending loop to sleep for some time, then increment the value of a global variable (which I immediately make public) if the value is less than the maximum value. I want to do this for several variables and I want all the code to be together, so I've used a simple switch statement on one of the script parameters -- may be a little ugly, but it keeps similar code together. The problem I'm having is that I get two errors per case.
The code looks like:
// Server side loop script to replenish available air support using mando_bombs.
// Arguments:
// name of the support type to replenish.
// Example:
// "BOMB_RUN" ExecVM "pbit_RegenerateSupport.sqf"
// Version: 0-0-1 (2008-03-27)
// Author(s): paritybit
// TODO: this should probably be changed, it's not very efficient.
if ( not isServer ) exitWith { };
private ["_loop", "_temp"];
_temp = _this select 0;
switch ( _temp ) do {
case "BOMB_RUN": {
for [{_loop=0}, {_loop<1}, {_loop=_loop}] do {
if ( mando_support_left_WEST < pbit_max_br ) then {
mando_support_left_WEST = mando_support_left_WEST + 1;
publicVariable "mando_support_left_WEST";
if (f_var_debugMode == 1) then {
player sideChat ("DEBUG: Added one bomb run resource point.");
};
};
sleep pbit_br_time;
};
};
case "HELO_ATTACK": {
for [{_loop=0}, {_loop<1}, {_loop=_loop}] do {
if ( mando_support_left_ca_WEST < pbit_max_ca ) then {
mando_support_left_ca_WEST = mando_support_left_ca_WEST + 1;
publicVariable "mando_support_left_ca_WEST";
if (f_var_debugMode == 1) then {
player sideChat ("DEBUG: Added one helo attack resource point.");
};
};
sleep pbit_ca_time;
};
};
// there are more cases, but I wanted the example to be shorter not longer
};
I've checked all of the global variables, they are all initialized with a value which I can print out prior to entering the switch (or even during the switch when I choose to).
The first error is:
Error in expression <upport_left_ve_WEST + 1;
publicVariable "mando_support_left_ve_WEST";
if (f_var_>
Error position: <"mando_support_left_ve_WEST";
if (f_var_>
Error Missing ;
I don't believe I'm missing a ; anywhere, I've looked -- maybe I'm going blind.
The second error is:
Error in expression <do_support_left_re_WEST < pbit_max_re ) then {
mando_support_left_re_WEST = mand>
Error position: <then {
mando_support_left_re_WEST = mand>
Error then: Type String, expected Array,code
I'm not sure what command is expecting an Array or code, or even what command is receiving a string.
I've tried so many different things; I tried moving the loop to the outside of the switch, thinking maybe the code inside each case was too complex for a case statement -- didn't work. I tried changing the for loop to a while (true) loop -- again no luck. I even tried changing the switch statement to a bunch of independent if statements -- nope. I tried removing the debug statements to see if that made a difference -- it didn't.
Any thoughts?
Thanks,
paritybit