Jump to content
Rebitaay

Need help: forEach returning an extra value

Recommended Posts

I'm making a script for my mission that selects all of the caches (placed in editor) and moves them to a random building, but that's besides the point.
In order to test a new method of moving them, I'm doing this to make sure they're being selected properly:

 

initServer.sqf

{[_x] execVM "Scripts\MoveCaches.sqf";} forEach [Cache1,Cache2,Cache3,Cache4,Cache5,Cache6];

MoveCaches.sqf

private "_cache";
_cache = _this select 0;
systemChat format["%1",_cache];

In system chat, Caches 1-6 appear, but there is also an extra "any" which is causing this error. Why is this happening, and how can I prevent it?

- Thanks

Share this post


Link to post
Share on other sites
9 minutes ago, killzone_kid said:

something else also calls moveCaches.sqf without argument

That was it! I've fixed the issue now, thank you!
And also, thank you for your many contributions to the wiki, and your tutorials. I kept seeing your name all over the place when learning to script, and your content has helped me a ton.

Share this post


Link to post
Share on other sites

Get all caches implicitly:

AllCaches = {
	private _res = []; private _obj = nil;
	while {_obj = missionNamespace getVariable "Cache" + str (count _res + 1); not isNil {_obj}} do {
		_res pushBack _obj}; _res
};


call AllCaches // Result: [Cache1,Cache2,Cache3,Cache4,Cache5,Cache6]

Share this post


Link to post
Share on other sites
1 hour ago, serena said:

Get all caches implicitly:


I raise you with this one liner
 

(allVariables missionNamespace select {_x find "cache" isEqualTo 0 && {_x select [5] call {str parseNumber _this isEqualTo _this}}}) apply {missionNamespace getVariable _x}

 

  • Like 1

Share this post


Link to post
Share on other sites
count allVariables missionNamespace // result for blank mission: 1308

xorsXI5.png

 

Faster than light :)

 

P.S. I like this:

_x select [5] call {str parseNumber _this isEqualTo _this}

 

  • Like 1

Share this post


Link to post
Share on other sites

Yeah but my script gets every and all Cache vars even if you have some missing in between

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, killzone_kid said:

I raise you with this one liner

No not the one line quiz again. :)

  • Like 3

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

×