Jump to content
Sign in to follow this  
bspendlove

Select from Array

Recommended Posts

Hello!

 

I am just having some issues with such code, need someone else's eyes to tell me what I am doing wrong! xD

_posArray = [[2903.08,6022.17,6.77022],[3025.04,5973.28,10.5211]];

checkpoint1 = createVehicle ["Sign_Circle_F",[_posArray select 0],[],0,"CAN_COLLIDE"];
//Also tried: createVehicle ["Sign_Circle_F",_posArray select 0,[],0,"CAN_COLLIDE"];

I was inputting all the co-ordinates for my checkpoints like such:

checkpoint3 = createVehicle ["Sign_Circle_F",[3114.27,5916.77,7.38084],[],0,"CAN_COLLIDE"];

But I feel having the co-ordinates in an array would be much neater.

 

I've tried:

_posArray = [[2903.08,6022.17,6.77022],[3025.04,5973.28,10.5211]];
_pos1 = _posArray select 0; // I've also tried _pos1 = [_posArray select 0];

checkpoint1 = createVehicle ["Sign_Circle_F",_pos1,[],0,"CAN_COLLIDE"];

Share this post


Link to post
Share on other sites
_posArray = [[2903.08,6022.17,6.77022],[3025.04,5973.28,10.5211]];
createVehicle ["Sign_Circle_F",_posArray select 0,[],0,"CAN_COLLIDE"];

works fine for me.

Share this post


Link to post
Share on other sites

Try this:

private ["_posArray"];

_posArray = [[2903.08,6022.17],[3025.04,5973.28]];

checkpoint1 = createVehicle ["Sign_Circle_F",_posArray select 0,[],0,"CAN_COLLIDE"];

It should work.

Share this post


Link to post
Share on other sites

Hmm, strange..

 

I tried what you put seba, but no luck.

 

Not creating the checkpoint using the: _posArray select 0

Share this post


Link to post
Share on other sites

As R3vo said, the code is working, so it should be something you haven't posted. Can you post the whole script?

Share this post


Link to post
Share on other sites

best practice would be to wrap in brackets to ensure it executes correctly

checkpoint1 = createVehicle ["Sign_Circle_F",(_posArray select 0),[],0,"CAN_COLLIDE"];
  • Like 1

Share this post


Link to post
Share on other sites

best practice would be to wrap in brackets to ensure it executes correctly

Entirely misinformation in this case. Your code looks fine as others have said.

 

Are you running with -showScriptErrors?

How/where are you executing the code?

Wrong classname maybe?

 

It's definitely not your syntax.

Share this post


Link to post
Share on other sites



_noeStart = noe_notice_student;

_reportBack = getMarkerPos "report_back_location";

private ["_posArray"];

_posArray = [[2903.08,6022.17,6.77022],[3025.04,5973.28,10.5211]];

fnc_create_noe = {

{ deleteVehicle _x; } forEach nearestObjects [position player,["Sign_Circle_F"], 4000];

titlecut ["Helicopter Checkpoint Training","BLACK IN",10];

titlecut ["","BLACK out",3];

sleep 0.2;

{ deleteVehicle _x; } forEach nearestObjects [position player,["B_Heli_Light_01_F"], 5];

_spawnStudentHelicopter = createVehicle ["B_Heli_Light_01_F", getMarkerPos "course_01_spawn",[],0,"FLY"];

_spawnStudentHelicopter setDir 123;

player moveInDriver _spawnStudentHelicopter;

titlecut ["Helicopter Checkpoint Training","BLACK IN",10];

sleep 0.6;

//Checkpoints

_checkpoint1 = createVehicle ["Sign_Circle_F",_posArray select 0,[],0,"CAN_COLLIDE"];

_checkpoint2 = createVehicle ["Sign_Circle_F",_posArray select 1,[],0,"CAN_COLLIDE"];

_checkpoint1 setDir 122;

_checkpoint2 setDir 107;

//Checkpoint Scores (Resets to 0 everytime the script has ran...)

_1cP = 0;

_spawnStudentHelicopter addAction ["<t color='#FF0000'>RTB</t>",{call fnc_clean;},[-1],12];

sleep 2;

while {true} do

{

_countCheckpoints = count nearestObjects [player, ["Sign_Circle_F"], 15];

if (_countCheckpoints > 0) then

{

playSound "soundCheckpoint";

_1cP = _1cP + 1;

{ deleteVehicle _x; } forEach nearestObjects [player ,["Sign_Circle_F"], 35];

hint format["%1 / 27 Checkpoints Passed", _1cP];

sleep 2;

hint "";

};

};

};

_noeStart addaction ["<t color='#00FFFF'>NOE Course 1</t>",{call fnc_create_noe;}];

Share this post


Link to post
Share on other sites

change 

_posArray = [[2903.08,6022.17,6.77022],[3025.04,5973.28,10.5211]];


fnc_create_noe = {

 to 

fnc_create_noe = {


_posArray = [[2903.08,6022.17,6.77022],[3025.04,5973.28,10.5211]];
  • Like 2

Share this post


Link to post
Share on other sites

 

-snip-

 

Many thanks, all working. :)

 

SOLVED

 

Edit-

 

Does anyone have a suggestion what I could look into to make it a bit neater/what method I should use to create my Checkpoints instead of doing: (or is this fine? I guess it would be more effective to just create a few, and move them upon entering a checkpoint?)

_checkpoint1 = createVehicle ["Sign_Circle_F",_posArray select 0,[],0,"CAN_COLLIDE"];
_checkpoint2 = createVehicle ["Sign_Circle_F",_posArray select 1,[],0,"CAN_COLLIDE"];
_checkpoint3 = createVehicle ["Sign_Circle_F",.........etc
_checkpoint4 = createVehicle ["Sign_Circle_F",.........etc
_checkpoint5 = createVehicle ["Sign_Circle_F",.........etc

Etc...?

 

Also if anyone could answer me, after setting the direction of the markers, I've heard it is useful to do something like:

_checkpoint1 setPos getPos _checkpoint1;

I've been having problems involving with the checkpoints not setting direction for other players for about 15 seconds, then it sets properly... like it doesn't Sync with all the other clients, maybe I just need to learn and read more :D

 

Thank you a ton for everyone's help. It is much appreciated !

Share this post


Link to post
Share on other sites

Does anyone have a suggestion what I could look into to make it a bit neater to create my Checkpoints instead of doing:

_checkpoint1 = createVehicle ["Sign_Circle_F",_posArray select 0,[],0,"CAN_COLLIDE"];
_checkpoint2 = createVehicle ["Sign_Circle_F",_posArray select 1,[],0,"CAN_COLLIDE"];
_checkpoint3 = createVehicle ["Sign_Circle_F",.........etc
_checkpoint4 = createVehicle ["Sign_Circle_F",.........etc
_checkpoint5 = createVehicle ["Sign_Circle_F",.........etc

Etc...?

 

for "_i" from 1 to _n do {call (compile (format ["_checkpoint%1 = createVehicle ['Sign_Circle_F', _posArray select %2, [], 0, 'CAN_COLLIDE'];", _i, _i - 1]))};

Also if anyone could answer me, after setting the direction of the markers, I've heard it is useful to do something like:

_checkpoint1 setPos getPos _checkpoint1;
I've been having problems involving with the checkpoints not setting direction for other players for about 15 seconds, then it sets properly... like it doesn't Sync with all the other clients, maybe I just need to learn and read more :D

 

https://community.bistudio.com/wiki/setDir - see notes.

  • Like 1

Share this post


Link to post
Share on other sites
-snip-

 

 

I can't thank you enough. You've been extremely helpful, much easier :D

Share this post


Link to post
Share on other sites

OK now that is much better :)

 

Before I continue to add all the directions into an Array, would a similar format work for setting each direction?

Share this post


Link to post
Share on other sites

 

best practice would be to wrap in brackets to ensure it executes correctly

checkpoint1 = createVehicle ["Sign_Circle_F",(_posArray select 0),[],0,"CAN_COLLIDE"];

 

 

Entirely misinformation in this case.

 

 

How is this misinformation, it may have been the cause of the problem! The use of the brackets (in this situation) is best practice!

Share this post


Link to post
Share on other sites

In this situation the use of brackets makes no difference, it's misinformation to suggest that it would.

_array = [1,2];
[_array select 0] isEqualTo [(_array select 0)]; // true
_array isEqualTo [_array select 0, _array select 1]; // true

Share this post


Link to post
Share on other sites

Are you planning on using your _checkpoint variables at some point? I don't recommend using call compile, and if you aren't going to use the variables anyway, you may as well not even store them. However, if you do plan on using them at some point, I'd recommend an array anyway instead of a bunch of separate variables.

_signs = [];
for "_i" from 0 to _n do
{
	_obj = createVehicle ["Sign_Circle_F", _posArray select _i, [], 0, "CAN_COLLIDE"];
	_signs pushBack _obj;
};

Share this post


Link to post
Share on other sites

 

best practice would be to wrap in brackets to ensure it executes correctly

checkpoint1 = createVehicle ["Sign_Circle_F",(_posArray select 0),[],0,"CAN_COLLIDE"];

 

 

How is this misinformation, it may have been the cause of the problem! The use of the brackets (in this situation) is best practice!

 

Commas are delimiters and even if you tried to "fool" them, e.g. by writing _a = [12, (3, 45), 6, 789], it gives you a syntax error:

 

Error in expression <_a = [12, (3, 45), 6, 789]>

Error position: <, 45), 6, 789]>

Error Missing )

 

... and if it doesn't, it's a bug and should be reported.

 

Because the interpreter evaluates:

12 - next, (3 - next -> ")" missing

 

So, putting brackets there is redundant to what the comma already handles and doesn't change anything, hence there's no justification to call it "best practice" other than possible benefits to readability if that's your intention. But as I already stated here, I'd rather make spaces between commas and words to improve readability than using unnecessary brackets.

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  

×