OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: XTimmy on 31 Dec 2008, 18:32:05

Title: If height >=10 then SAY SOMETHING
Post by: XTimmy on 31 Dec 2008, 18:32:05
Hey.
I've been working on my 'first' mission for a few days now and it's beginning to grind ever so slightly.  I've reached a point where I need a function rather than a script.
Then I decided a Trigger would work just as well.
Basically I've got a helicopter rising in the distance. And when it hits a certain height (10) Crossroads says something to the affect of 'oh no'

I simply cannot get this to work.   

My current set up  (which dosen't return an error, it simply returns nothing is thus)
A trigger, axis a/b = 0/0,
Condition:
(getpos testheli select 2) >= 10
On Act
[sidefriendly, "HQ"] Sidechat "oh no"

I've tried variations of everything [side, "HQ"] Sidechat "oh no"   etc etc but it simply dosen't pop up. Any thoughts? 

(If someone could also make this into a .sqf so I've got an example function to learn the syntax for a looping script off that'd be great)
Title: Re: If height >=10 then SAY SOMETHING
Post by: Deadfast on 31 Dec 2008, 18:43:44
Try this:

Code: [Select]
HQ = [west, "HQ"]; HQ sideChat "Oh no!";


Here's the SQF:
Code: [Select]
while {alive testheli} do //loop as long as testheli is alive
{
if ((getPos testheli select 2) >= 10) then //check if testheli's height is greater or equal 10
{
HQ = [west, "HQ"];
HQ sideChat "Oh no!";
};

sleep 1; //wait 1 second before continuing - always sleep if the loop runs for extended amount of time or the game will freeze!
};
Title: Re: If height >=10 then SAY SOMETHING
Post by: XTimmy on 01 Jan 2009, 00:56:33
Sleep is exactly the command I've been looking for! 
Thanks for the help in both threads Deadfast!  :D
Title: Re: If height >=10 then SAY SOMETHING
Post by: Deadfast on 01 Jan 2009, 02:37:06
You're much welcome :)


I wish you good luck in learning SQF ;)
Title: Re: If height >=10 then SAY SOMETHING
Post by: Ext3rmin4tor on 01 Jan 2009, 12:24:43
There is also waitUntil

which is equivalent to @ in SQS scripts if you're interested
Title: Re: If height >=10 then SAY SOMETHING
Post by: Deadfast on 01 Jan 2009, 12:44:14
IIRC waitUntil eats up more resources so I'd personally avoid it in this case ;)


BTW Timmy, I just realized you might want to have the message display only once.

In that case use exitWith instead of then with the if condition (it's similar to break in C-like languages):

Code: [Select]
while {alive testheli} do
{
if ((getPos testheli select 2) >= 10) exitWith //if the condition is true execute the code and then exit the while cycle scope
{
HQ = [west, "HQ"];
HQ sideChat "Oh no!";
};

sleep 1;
};
Title: Re: If height >=10 then SAY SOMETHING
Post by: XTimmy on 01 Jan 2009, 13:14:34
Nice to know but it only needs to execute once.
Title: Re: If height >=10 then SAY SOMETHING
Post by: Deadfast on 01 Jan 2009, 15:43:52
Yep, that's why you need exitWith ;)