Home   Help Search Login Register  

Author Topic: [SOLVED] Error "Type String, expected Array,code"  (Read 3685 times)

0 Members and 1 Guest are viewing this topic.

Offline paritybit

  • Members
  • *
[SOLVED] Error "Type String, expected Array,code"
« on: 09 Apr 2008, 07:46:19 »
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:
Code: [Select]
// 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:
Code: [Select]
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:
Code: [Select]
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
« Last Edit: 09 Apr 2008, 23:38:32 by paritybit »
Heroes don't die -- they just respawn.

Offline Rommel92

  • Members
  • *
Re: Error "Type String, expected Array,code"
« Reply #1 on: 09 Apr 2008, 08:31:57 »
Code: [Select]
for [{_loop=0}, {_loop<1}, {_loop=_loop}] do {
Should that be:
Code: [Select]
for [{_loop=0, {_loop<1},{_loop = _loop +1}] do {

Unless your looking for a loop that only ends when _loop is above 1, in which case anyway...
Code: [Select]
While {_loop < 1} do
{
//code
};
« Last Edit: 09 Apr 2008, 21:39:25 by Rommel92 »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Error "Type String, expected Array,code"
« Reply #2 on: 09 Apr 2008, 15:51:28 »
Your supplied code above does not include any such examples as the errors reported.

mando_support_left_ve_WEST

and

mando_support_left_re_WEST

Neither of these lines are included in your code example.


Planck
I know a little about a lot, and a lot about a little.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Error "Type String, expected Array,code"
« Reply #3 on: 09 Apr 2008, 17:02:56 »
Your code seems good, the problem might be related to variable types (the one used in the switch, for example). Anyway, your for _loop is a bit weird, you might change it by a simple while {true} do {

Offline paritybit

  • Members
  • *
Re: Error "Type String, expected Array,code"
« Reply #4 on: 09 Apr 2008, 18:28:36 »
I tried a while (true) loop, which did not help.  I used the strange for loop on the advice of another scripter who suggested it was a way around the 10,000 loop limitation of a while loop.  Maybe I've been misguided?  In either case, the switch to a while loop did not help and the errors are the same. 

EDIT: I've also checked the variable used in the switch -- it is a string which I expect; perhaps there's a problem with switching on a string that I am unaware of?  I've also printed the value prior to entering the switch and it is as expected.  in fact, I am able to enter the switch statement, but once inside I see the errors indicated.

Quote from: Planck
Neither of these lines are included in your code example.

Those lines are in Mandoble's air support scripts; I've checked that at the time my script is called the values are set (the variables are not nil) and valid.  The variables prefixed with pbit are mine, and I've verified that at the time this script is called they are also set and valid.
« Last Edit: 09 Apr 2008, 23:22:06 by h- »
Heroes don't die -- they just respawn.

Offline Rommel92

  • Members
  • *
Re: Error "Type String, expected Array,code"
« Reply #5 on: 09 Apr 2008, 21:38:51 »
So what indicates that the error is in this script, if the coding is from another?  :dunno:

Offline paritybit

  • Members
  • *
Re: Error "Type String, expected Array,code"
« Reply #6 on: 09 Apr 2008, 23:11:21 »
I wouldn't say the coding is from another script; there are variables that are defined and initialized in another script, but all of the coding is contained within this script -- there are no functions or other scripts being called from the area where the error is being seen.  And, the ArmA errors are being shown as in my script.  I've seen the error line reporting wrong, but never outside of the script where the error is occurring.  Granted, I am fairly new to ArmA scripting.

To see the entire flow, I've put the relevant files into pastebin.  The init.sqf calls init_server.sqf which calls pbit_RegenerateSupport.sqf.  Click on the name of the file to see the link with full contents.

Actually, I've not included the whole init.sqf as it is largely irrelevant to this conversation.  It was working fine before I added this new component.  There are alternate versions where I call the pbit_RegenerateSupport.sqf script without brackets around the parameter (and instead use just a string in quotes such as "CAP") but it executes with the same outcome and so I figured the syntax was equivalent and went with the one I had last used.

EDIT: By the way, if you're like me and haven't heard of pastebin until yesterday (well, okay for you guys it would be today) go to pastebin.com and check it out.  You can, optionally, add a subdomain name (as I did, to make it paritybit.pastebin.com) which makes it likelier that only your stuff is linked on the page people browse to.  It's one of the coolest websites I've seen in a long time.

EDIT 2: Hold the presses.  I've solved the problem.  I accidentally used "publicVariable = someVariable" instead of "publicVariable someVariable".  Apparently, that tracked all the way into another script.  Maybe it caused "publicVariable" to have a value which screwed up the use of the command?  If you want to see the offending line, look on line 55 of server_init.sqf (linked above via pastebin); this is some distance from the locations of the errors reported by ArmA (two for every case that was called in the switch statement).  The messages gave absolutely no clue as to what the real problem was -- hopefully this helps someone else as clueless as me.  On the bright side, I now have a sort of "rechargable" over time mando bombs script which works very well.  The number of planes available for bombing runs (and other assorted mando goodies) will slowly increase over time to reach the maximum amount -- where the number will stop growing until used again.
« Last Edit: 09 Apr 2008, 23:41:22 by paritybit »
Heroes don't die -- they just respawn.