Jump to content
Sign in to follow this  
Myn

Iterative Vehicle Spawn - iteration problem?

Recommended Posts

Hey guys,

Quick question for the more experienced scripters out there, who will undoubtedly tell me that this is a bad idea in the first place, but I'm having an issue with an iterative spawn.

for [{_x=1},{_x<=10},{_x=_x+1}] do {
 _car1 = objNull;
 _man1 = objNull;
 _grp1 = createGroup civilian;
 _car1 = createVehicle ["car_hatchback", getMarkerPos "Spawn1E", [], 0, "CAN_COLLIDE"];
 _car1 setPos getMarkerPos "Spawn1E";
 _man1 = _grp1 createUnit ["RU_Worker1", getMarkerPos "Spawn1E", [], 0, "CAN_COLLIDE"];
 _man1 moveInDriver _car1;
 _wp = _grp addWaypoint [getMarkerPos "WPEast", 0];
 _wp setWaypointType "MOVE";
 _wp setWaypointBehaviour "CARELESS";
 _wp setWaypointSpeed "LIMITED";
 sleep 5;
};

What it is meant to do: create ten cars with drivers at one single position at 5 second intervals, assigning them a predefined waypoint to follow.

What is actually does: creates one car with a driver, assigns it the waypoint, which it follows, then stops.

Interestingly, if I take the loop out of the script and loop the script call instead, this works fine (except without intervals).

If anyone would be able to enlighten me on why this might not be working, I would greatly appreciate it.

Thanks in advance,

M

Share this post


Link to post
Share on other sites

im not about to test your code. but i see this.

_grp1 = createGroup civilian;

then you use

_wp = _grp addWaypoint [getMarkerPos "WPEast", 0];

make it _wp = _grp1

Share this post


Link to post
Share on other sites

Your loop technically is working, what it's doing though is spawning the vehicles on top of each other and they aren't listening to the waypoint. Here's what I changed:

for [{_x=1},{_x<=10},{_x=_x+1}] do {
 _grp1 = createGroup civilian;
 _car1 = createVehicle ["car_hatchback", getMarkerPos "Spawn1E", [], 0, "CAN_COLLIDE"];
 _car1 setPos getMarkerPos "Spawn1E";
 _man1 = _grp1 createUnit ["RU_Worker1", getMarkerPos "Spawn1E", [], 0, "CAN_COLLIDE"];
 _man1 moveInDriver _car1;
 _wp = _man1 doMove (getMarkerPos "WPEast");
 sleep 5;
};

This will spawn a vehicle, it will drive to the waypoint and then another will spawn. Works great, just tested.

Share this post


Link to post
Share on other sites

Nuxil: Sorry, you're right of course; I re-wrote the code here from an un-networked machine I'm running ARMA II on in a rush and must have left that out, but that was correct in the working copy. Sorry about that.

Gossamer: Thanks, I'll give that a go in a minute, but are you sure they're spawning on top of each other? When I was testing that code it was spawning just one, who did follow the waypoint, but none after it.

(I've just copied your code directly into a script, called it in-game, and had the same issue; only the first car spawns)

Edit: Just to add further detail, I copied the code directly into an empty script called spawn_east.sqs and called it by a Radio trigger with [ ] exec "spawn_east.sqs"

Both my code and Gossamer's only create one vehicle, which follows the waypoint, but does not seem to loop round.

Edit(2): I've just done further testing by adding a rifleman _sol and adding

_sol fire "m16a4"

to the loop. The rifleman fires once only, so I would maintain that either there is a problem with the loop in the script or a problem with how I am calling the script; I honestly cannot think of what either problem might be though.

Edit(3): Right, further progress:

I printed _x within the loop and found out that _x is "any". I also tried:

_x = 42;
hint format ["External var: %1",_x];
for [{_x=1},{_x<=10},{_x=_x+1}] do {
 sleep 5;
 hint format ["Internal var: %1",_x];
};

Which outputted External var:42 and Internal var:42 rather than Internal var:1. Also the "sleep 5" didn't work.

As far as I know the code is correct, is this a problem with how I'm calling it?

Edited by Myn

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  

×