Jump to content
Sign in to follow this  
Llano

Undefined variable array?

Recommended Posts

Hello.

So have the following code:

	_nickArray = call compile _resultNick;
	_nickArray = _nickArray select 0 select 0;
	_notFound = true;

	{
		if(_x != _name) then
		{
			_notFound = false;
		}
	} 
	foreach _nickArray;

when irun it, it give me the error

Error ==: Undefined variable in expression: _nickArray

I have defined the variable, so why does it complain about it?

Share this post


Link to post
Share on other sites

Couple of questions:

What is _name ?

What is _resultNick?

Can't see what you're doing with them at the moment.

Share this post


Link to post
Share on other sites

Obviously, nowhere in your code did you do _nickArray = ... anywhere in the script, or alternatively the ... resulted in an undefined value as well.

Share this post


Link to post
Share on other sites
Couple of questions:

What is _name ?

What is _resultNick?

Can't see what you're doing with them at the moment.

_name is the name of the player

_resultNick is an array with player nicknames from my database

Obviously, nowhere in your code did you do _nickArray = ... anywhere in the script, or alternatively the ... resulted in an undefined value as well.

I do? 1st row?

_nickArray = call compile _resultNick;

Share this post


Link to post
Share on other sites

And _name is ? The following line is strange :

_nickArray = _nickArray select 0 select 0;

Couldn't it be

_name = _nickArray select 0;

instead ?

Share this post


Link to post
Share on other sites

It looks like an array of an array of names to me.

Could you put up a sample so I can have a look?

Share this post


Link to post
Share on other sites
And _name is ? The following line is strange :

_nickArray = _nickArray select 0 select 0;

Yeah, i had to do so, because it was nested arrays (using arma2netmysqlplugin), and it was the only way i found to do it (someone posted it in the thread) :)

---------- Post added at 20:34 ---------- Previous post was at 20:32 ----------

It looks like an array of an array of names to me.

Could you put up a sample so I can have a look?

[[["Foxie"], ["Llano"]]]

that is what _nickArray contains.

Maybe i screwed it up with my select? :)

---------- Post added at 20:42 ---------- Previous post was at 20:34 ----------

And _name is ? The following line is strange :

_nickArray = _nickArray select 0 select 0;

Couldn't it be

_name = _nickArray select 0;

instead ?

Nope, that gave me error.

"type bool, expected number, string.. etc".

Share this post


Link to post
Share on other sites
_name is the name of the player

_resultNick is an array with player nicknames from my database

If _resultNick is an array, why are you calling "call" on it? The parameter for call needs to be a valid SQF statement.

Share this post


Link to post
Share on other sites

_resultNick is an array with player nicknames from my database

Please post an example of an actual output, do

diag_log _resultNick

I'm pretty sure you'll find it's not what you expect it to be.

Share this post


Link to post
Share on other sites

Ok, i begin to understand, but

[[["Foxie"], ["Llano"]]] select 0 is [["Foxie"], ["Llano"]]

And [["Foxie"], ["Llano"]] select 0 is ["Foxie"], which isn't what you wanted it to be.

Share this post


Link to post
Share on other sites

And [["Foxie"], ["Llano"]] select 0 is ["Foxie"], ["Llano"], which isn't an array.

Huh?

[[["Foxie"], ["Llano"]]] select 0 => [["Foxie"], ["Llano"]]
[["Foxie"], ["Llano"]] select 0 => ["Foxie"]
["Foxie"] select 0 => "Foxie"

Share this post


Link to post
Share on other sites

This test code runs ok on my PC:

private ["_notFound","_nickArray","_name"];

_nickArray = [[["Foxie"], ["Llano"]]];
_nickArray = _nickArray select 0 select 0;
diag_log format ["NICKARRAY%1", _nickArray];

_name = "name";

_notFound = true;

{
if (_x != _name) then
{
	_notFound = false;
}
} foreach _nickArray;

diag_log format ["NOTFOUND %1", _notFound];

Returns the following:

"NICKARRAY["Foxie"]"
"NOTFOUND false"

Only problem I can see is that you are checking the elements in the wrong places, so ATM it only checks the first element of your array. The following works:

private ["_notFound","_nickArray","_name"];

_nickArray = [[["Foxie"], ["Llano"]]];
_nickArray = _nickArray select 0;
diag_log format ["NICKARRAY%1", _nickArray];

_name = "name";

_notFound = true;

{
if (_x select 0 != _name) then
{
	_notFound = false;
}
} foreach _nickArray;

diag_log format ["NOTFOUND %1", _notFound];

Returning the following:

"NICKARRAY[["Foxie"],["Llano"]]"
"NOTFOUND false"

EDIT: I would probably also check for a true, rather than false in your loop (but that's just me - depends on what you want it to do). Maybe also look at exitWith or breakTo so you can exit the loop once your condition is true. Might be more efficient if you have lots of players to check.

Something like:

private ["_found","_nickArray","_name"];

_nickArray = [[["Foxie"], ["Llano"]]];
_nickArray = _nickArray select 0;
diag_log format ["NICKARRAY: %1", _nickArray];

_name = "name";

_found = false;

{
if (_x select 0 == _name) exitWith
{
	_found = true;
}
} foreach _nickArray;

diag_log format ["FOUND: %1", _found];

Edited by Das Attorney

Share this post


Link to post
Share on other sites

Heh, sorry guys. Seems like i passed the wrong array to the foreach-loop, causing it always to be null.

I made it work now, but thanks for trying to help me :)

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  

×