Jump to content
Sign in to follow this  
Capt. Eduardo del Mango

My semicolons have gone awry! Getmarkerpos getting pos of the wrong marker.

Recommended Posts

Hello!

Firstly, thanks in advance for any replies. Despite owning BIS games since OFP's UK release date I've only recently gotten sucked down the mission editing rabbit-hole. Two weeks ago I just wanted to make a little army man stand in the right place while I shot him and now I'm arse-deep in semicolons and three different types of parenthesis trying to make the little fuckers just STAND STILL FOR CHRIST'S SAKE.

Ahem.

Specific problem is this; I've got two sites, alpha and bravo, defended by independent by two patrols each (AP1 and AP2 at alpha, BP1 and BP2 at bravo). When independent detects BLUFOR within a trigger radius the following runs;

deleteWaypoint [AP1, all];wap1 = AP1 addWaypoint [getmarkerpos "ap1guard", 0];wap1;AP1 setcurrentwaypoint [AP1, 0];[AP1, 0] setWaypointType "Guard";ap1 setbehaviour "Aware";deleteWaypoint [AP2, all];wap2 = AP2 addWaypoint [getmarkerpos "ap2guard", 0];wap2;AP2 setcurrentwaypoint [AP2, 0];[AP2, 0] setWaypointType "Guard";AP2 setbehaviour "Aware";

Which deletes the existing waypoints, creates a variable* to generate new ones for AP1 at ap1guard and AP2 at ap2guard (which have adjacent 'guarded by independent' triggers), runs that variable and sets them to it. This works fine for alpha, but for some reason when I use the following for bravo;

deleteWaypoint [bP1, all];wBP1 = BP1 addWaypoint [getmarkerpos "bp1guard", 0];wBP1;BP1 setcurrentwaypoint [bP1, 0];[bP1, 0] setWaypointType "Guard";BP1 setbehaviour "Aware";deleteWaypoint [bP2, all];wBP2 = BP2 addWaypoint [getmarkerpos "bp2guard", 0];wBP2;BP2 setcurrentwaypoint [bP2, 0];[bP2, 0] setWaypointType "Guard";BP2 setbehaviour "Aware";

BP1 and BP2 go running off to ap1guard and ap2guard and I have no idea why. First person to step up and tell me my incredibly obvious novice error gets half an internet and use of the goat tower for a day.

Cheers,

-Eduardo

*Because "group addWaypoint [center, radius] or [center, radius, index]" didn't work for me as described in the comref - gave 'type array, expected nothing'.

Edited by Capt. Eduardo del Mango

Share this post


Link to post
Share on other sites

Structure your code better to find errors like this, or turn on -showScriptErrors when you start your game.

deleteWaypoint [AP1, all];
wap1 = AP1 addWaypoint [getmarkerpos "ap1guard", 0];
wap1;
AP1 setcurrentwaypoint [AP1, 0];
[AP1, 0] setWaypointType "Guard";
ap1 setbehaviour "Aware";
deleteWaypoint [AP2, all];
wap2 = AP2 addWaypoint [getmarkerpos "ap2guard", 0];
wap2;
AP2 setcurrentwaypoint [AP2, 0];
[AP2, 0] setWaypointType "Guard";
AP2 setbehaviour "Aware";

If you restructure your code so it's human readable instead of trying to have everything on one line it becomes quite obvious where your errors were. :) wap1; does nothing and your syntax is all messy.

This might be better:

deleteWaypoint [AP1, all];
wap1 = AP1 addWaypoint [getmarkerpos "ap1guard", 0];
wap1 setWaypointType "Guard";
AP1 setcurrentwaypoint [AP1, 0];
AP1 setbehaviour "Aware";

deleteWaypoint [AP2, all];
wap2 = AP2 addWaypoint [getmarkerpos "ap2guard", 0];
wap2 setWaypointType "Guard";
AP2 setcurrentwaypoint [AP2, 0];
AP2 setbehaviour "Aware";

However, remember Guard waypoints only work to move units to Guarded By triggers. It's not for use in "protecting" an area.

Share this post


Link to post
Share on other sites

Hi kylania,

Thanks very much for the reply! Firstly, yep - hadn't even thought about how to lay it out to read it better. Like I said, two weeks ago I was under the impression I was just putting down little icons - all this 'syntax' stuff has somewhat surprised me.

When I did;

wap1 = AP1 addWaypoint [getmarkerpos "ap1guard", 0];
wap1;

I thought I was creating a variable (wap1) that added the waypoint, and then running the variable by just having wap;.

With the code in my original configuration;

deleteWaypoint [AP1, all];
wap1 = AP1 addWaypoint [getmarkerpos "ap1guard", 0];
wap1;
AP1 setcurrentwaypoint [AP1, 0];
[AP1, 0] setWaypointType "Guard";
ap1 setbehaviour "Aware";
deleteWaypoint [AP2, all];
wap2 = AP2 addWaypoint [getmarkerpos "ap2guard", 0];
wap2;
AP2 setcurrentwaypoint [AP2, 0];
[AP2, 0] setWaypointType "Guard";
AP2 setbehaviour "Aware";

It did work as intended. AP1 and AP2 both immediately became alert and moved straight to the guard waypoints. Changing to the code you suggested actually stops it working - AP1 and AP2 continue on their patrols (although I'm new at this so I'm not sure why that'd happen).

That all works fine - the only problem is with;

deleteWaypoint [bP1, all];
wbp1 = BP1 addWaypoint [getmarkerpos "bp1guard", 0];
wbp1;
BP1 setcurrentwaypoint [bP1, 0];
[bP1, 0] setWaypointType "Guard";
bp1 setbehaviour "Aware";
deleteWaypoint [bP2, all];
wbp2 = BP2 addWaypoint [getmarkerpos "bp2guard", 0];
wbp2;
BP2 setcurrentwaypoint [bP2, 0];
[bP2, 0] setWaypointType "Guard";
BP2 setbehaviour "Aware";

Which also works entirely as expected, except getmarkerpos seems to be picking up ap1guard and ap2guard instead of bp1guard and bp2guard - but they run change to 'aware' and move straight towards it as they should to bp1/2guard. Once they're there they guard at the 'guarded by independent' triggers correctly.

Share this post


Link to post
Share on other sites

I thought I was creating a variable (wap1) that added the waypoint, and then running the variable by just having wap;.

The part to the left of the = when using a command is a variable that stores the return value of the command, the command will still execute at that point. So in that example wap1 becomes a reference to the waypoint created by the addWaypoint command. That's why later you can either use [GroupName, WaypointIndex] or simply wap1 to refer to the waypoint when say using setWaypointType command.

The comref will tell you the data type of the return value so you know how to use it.

With the code in my original configuration;

wap1 = AP1 addWaypoint [getmarkerpos "ap1guard", 0];
AP1 setcurrentwaypoint [AP1, 0];
[AP1, 0] setWaypointType "Guard";

It did work as intended. AP1 and AP2 both immediately became alert and moved straight to the guard waypoints. Changing to the code you suggested actually stops it working - AP1 and AP2 continue on their patrols (although I'm new at this so I'm not sure why that'd happen).

Haven't had time to test either set of code to be honest since I'm at work and it's stupidly busy. :) If you're trying to have a situation where you have a group following a patrol route then you want to the be able to respond to specific conflict point you can do that with a cycle waypoint and a switch trigger instead of clearing out waypoints and using Guard waypoints.

This demo here shows that (you can additionally reset the patrol by changing the current waypoint to 0 but I don't think I have that in that demo). You have a Hind patrolling over an airfield then based on an enemy detected in one of three cities it'll respond to that, then go back on it's patrol.

Which also works entirely as expected, except getmarkerpos seems to be picking up ap1guard and ap2guard instead of bp1guard and bp2guard - but they run change to 'aware' and move straight towards it as they should to bp1/2guard. Once they're there they guard at the 'guarded by independent' triggers correctly.

Maybe check that you didn't get any marker names wrong? That does sound odd. :(

Share this post


Link to post
Share on other sites

I'm using this method because the patrol loops are pretty big - it could be a while before they get to the synched waypoint to move. Given this should be fairly straightforward (welcome to Arma2 editing, right?) I thought this'd be preferable... Marker names are definitely right too.

Haven't had time to test either set of code to be honest since I'm at work and it's stupidly busy.

Ah, well thanks very much for taking the time you already have! Don't worry, I'm proving quite expert at breaking Arma2 so far, I'm sure it's something bizarre I've done somewhere along the line. Thanks for your help, kylania.

Edited by Capt. Eduardo del Mango

Share this post


Link to post
Share on other sites
I'm using this method because the patrol loops are pretty big - it could be a while before they get to the synched waypoint to move.

Try the demo, it doesn't matter how many waypoints are before the cycle, if you switch it via trigger all the previous waypoints are skipped. So say you have 3 waypoints followed by a cycle followed by a search and destroy and you trip the cycle before you even get to waypoint 1 and the AI will travel directly to the S&D waypoint.

Share this post


Link to post
Share on other sites
if you switch it via trigger all the previous waypoints are skipped.

Aaaaargh!

Heh heh. Oh, deary me, that would've been good to know two days ago! In my defence the BIS wiki doesn't mention that's how it works...

Excellent, cheers kylania! Thanks for all your help here!

Still curious as to why it didn't work in the first place, though. Although I'm equally pleased to have broken Arma2 in a way that seems to have perplexed a very experienced scripter like yourself! Perhaps BIS should hire me in for testing? :D

Thanks again,

-Eduardo

Edited by Capt. Eduardo del Mango

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  

×