Jump to content
Sign in to follow this  
Jak2039

Scripted Waypoint not allowing IF

Recommended Posts

Hi all

I've been trying my hand at scripting past few days, but I've reached a wall with the scripted waypoints. I directed the waypoint to run my script, which it did fine and well, but it won't execute IF statements properly. It always returns 'any'.

if (dayTime >= 19 or dayTime <= 5) then

I know my coding gets rough, but no matter what I try, it doesn't pass as true, and simply jumps to the else statement. Any ideas as to what is wrong?

Share this post


Link to post
Share on other sites

You don't have to use the Scripted Waypoint since the On Act field can do the same thing at any kind of Waypoint.

Can you post the rest of your script? First glance you might wanna use:

if ((dayTime >= 19) || (dayTime <= 5)) then

But it would help to see the rest.

Share this post


Link to post
Share on other sites

_WPHome = getMarkerPos "_MOVEHEREHOME";
private "_WaypointArray";
_WaypointArray = [_WP1, _WP2, _WP3, _WP4];
_WP1 = getMarkerPos "_MOVEHERE1";
_WP2 = getMarkerPos "_MOVEHERE2";
_WP3 = getMarkerPos "_MOVEHERE3";
_WP4 = getMarkerPos "_MOVEHERE4";
private "_CompletedWP";
private "_RemoveWP";
_NextWP = _WaypointArray select 1;
_Hour = Date select 3;



for [{_i=1}, {_i>=1}, {_i=_i+1}] do
{
if (dayTime >= 19 OR dayTime <= 5) then
{
	_this doMove _NextWP;
	_RemoveWP set [1, _NextWP];
	_WaypointArray = _WaypointArray - _RemoveWP;
};
else
{
	_this doMove _WPHome;
};
};

I'm trying to make a chopper fly around a bunch of waypoints but only at night and since I lack the knowledge necessary, it involves trying everything I can think of. Some of the variables need removing as well I think, not sure whether I even need some of it.

I should also note that if

if (dayTime >= 19 OR dayTime <= 5) then

is replaced with

while {alive player} do

also does not work.

Edited by Jak2039
Additional info

Share this post


Link to post
Share on other sites

A few things your syntax around the else is wrong try } else { also how do you plan on making it move as I can't see how your incrementing _NextWP with _WaypointArray select 1;

Are your markers named "_MOVEHERE1" or "MOVEHERE1" I don't see the need for the underscore

The time of day works perfectly.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

It's just a work in progress, I was more concerned with getting past the first couple of lines, then figuring out how to do the waypoint progression. The else works fine, I added some hints after it to report several quantities, including date and daytime, which is successfully does.

Here's some more things I've tried.

if (daytime >= 19 or dayTime <= 5) then
{
	_this doMove (getMarkerPos "MOVEHERE1");
};

_Zero = 0;

if (_Zero == 1) then
{
	_this doMove (getMarkerPos "MOVEHERE1");
};

Regardless of whether the IF returns TRUE or FALSE, the chopper moves to the waypoint. I'm using the scripted waypoint simply because I find it easier to write script in a text file, rather than the box in the editor. No, I didn't mean to put in the underscores, but it doesn't make a difference since everything done under Then isn't executed anyway.

Share this post


Link to post
Share on other sites

I have it working and going to the four markers, it needs work to make it useful but it's a start. I also bypassed the _nextWP variable and removed the remove bits as that was removing them in the wrong order I think. More likely because I don't use _NextWP

had to add choppers name when calling the script and I renamed the markers for my own use without _.

I put a sleep of 40 secs you may want this to be longer and needs changing to something else.

I used a jeep for testing as choppers are two slow.

_unit = _this select 0;
_WPHome = getMarkerPos "MOVEHEREHOME";
private "_WaypointArray";

_WP1 = getMarkerPos "MOVEHERE1";
_WP2 = getMarkerPos "MOVEHERE2";
_WP3 = getMarkerPos "MOVEHERE3";
_WP4 = getMarkerPos "MOVEHERE4";
_WaypointArray = [_WP1, _WP2, _WP3, _WP4];
private "_CompletedWP";
private "_RemoveWP";
_NextWP = _WaypointArray select 1;
_Hour = Date select 3;



for [{_i=1}, {_i<=4}, {_i=_i+1}] do
{
if (dayTime >= 19 OR dayTime <= 5) then
{

	hint format[" %1",_i];
	_unit doMove   (_WaypointArray select _i);
	//_RemoveWP set [1, _NextWP];
	// _WaypointArray = _WaypointArray - _RemoveWP;
	sleep 40;
} else {
	_unit doMove _WPHome;
};
};

Edited by F2k Sel

Share this post


Link to post
Share on other sites

I copy and pasted that into the txt file, but it just came up hinting 'any', then no movement. I tried it both after and before the times in the IF.

May I ask where you ran the script from?

Share this post


Link to post
Share on other sites
I copy and pasted that into the txt file, but it just came up hinting 'any', then no movement. I tried it both after and before the times in the IF.

May I ask where you ran the script from?

This placed in the units init line null=[this] execVM "waypoints.sqf" if your using a trigger you will need to name the chopper and replace [this] with the name of the chopper

Share this post


Link to post
Share on other sites

Thanks, you've been a great help. Does this mean scripts ran in the Scripted Waypoints don't support If statements? Like I said before, they won't even run simple scripts. I'm sure I tried them in the On Activation field as well.

Share this post


Link to post
Share on other sites

I haven't done any scripted waypoints as yet these are just using markers pretending to be waypoints.

I did do a scripted trigger and found the syntax very strange.

if you place this in the On Act box of a waypoint placed through the editor it works so I carn't see why it won't work in a scripted waypoint with the right syntax.

 if (dayTime >= 19 OR dayTime <= 5) then { hint "true"};

Share this post


Link to post
Share on other sites
I haven't done any scripted waypoints as yet these are just using markers pretending to be waypoints.
You don't have to use the Scripted Waypoint since the On Act field can do the same thing at any kind of Waypoint.

Both of this is not true. Have a look into the "How to use waypoint SCRIPTED" thread at ofpec.com

The SCRIPTED waypoint will pass parameters to the script which is not the case when you run a script from the On Activation line of any waypoint (even a SCRIPTED waypoint).

I've been trying to use a SCRIPTED waypoint in Arma2 myself and had to notice that it not only doesn't execute if statements properly but also refuses to execute for and foreach loops (and probably while loops as well but I did not test that).

There also is low or invalid info in the Biki regarding SCRIPTED waypoints which says that they are redundant and don't have any special value. Well maybe this is true in Arma2 because scripts called from SCRIPTED waypoints do not execute control structures properly.

Share this post


Link to post
Share on other sites

Maybe it's just a shortcut with "exec" command, to run SQS scripts. Obviously SQF stuff wouldn't work.

Share this post


Link to post
Share on other sites

You are right shk, I tried it with sqs instead of sqf and it worked.

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  

×