Jump to content
Sign in to follow this  
bobby budnick

Vehicle (roadcone) not named correctly when created with forEach - a short example

Recommended Posts

HQ_ARRAY = [COMPANY_1_HQ];
{

_x = "RoadCone" createVehicle (getPos player);

} forEach HQ_ARRAY;

It should be named COMPANY_1_HQ but I know it is not named correctly because I can not setPos myself to it. This one has to be simple because it is so short but I cannot figure it out. What could be happening here?

Share this post


Link to post
Share on other sites

try call compile format["%1 = 'RoadCone' createVehicle (getPos player)",_x];

instead of _x = "RoadCone" createVehicle (getPos player);

Edit: Make the variable a string too.

so HQ_ARRAY = ["COMPANY_1_HQ"];

Putting a variable in a array like that just grabs the value of it and stuffs it into the array.

Pretty logical infact.

Anyway previous example should work.

Edited by headswe

Share this post


Link to post
Share on other sites

I would have died from old age or boredom before I figured out that one. So you use "call compile" when you have some code in a format statement that you need to actually run. Yeah making the company name a string should have been obvious. A third mistake I was making that you helped with was I was using format and createVehicle like this:

format["%1", _x] = "RoadCone" createVehicle (getPos player);

which gave errors instead of your way with format wrapped around the entire statement. I still don't know why that gives errors though. I think it should work!

So thanks a lot. You helped with three different things. I'm on a marathon right now and this will keep me from being bogged down.

Edited by Bobby Budnick

Share this post


Link to post
Share on other sites
I would have died from old age or boredom before I figured out that one. So you use "call compile" when you have some code in a format statement that you need to actually run. Yeah making the company name a string should have been obvious. A third mistake I was making that you helped with was I was using format and createVehicle like this:

format["%1", _x] = "RoadCone" createVehicle (getPos player);

which gave errors instead of your way with format wrapped around the entire statement. I still don't know why that gives errors though. I think it should work!

So thanks a lot. You helped with three different things. I'm on a marathon right now and this will keep me from being bogged down.

The reason why that wouldent work is the fact it would be

"STRINGHERE" = "RoadCone" createVehicle (getpos player) .

format returns a string

compile takes a string and turns it into a {} (code boject)

call well.. executes a code object.

No problem by the way.

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  

×