Jump to content
Sign in to follow this  
breyz

alive _guy? script issue

Recommended Posts

if (!isserver) exitWith {};
private ["_guy","_delay"];
_guy = _this select 0;
_delay= _this select 1;

sleep _delay;

while {alive _guy} do
{ 

p3 playmove "AmovPercMstpSnonWnonDnon_idle71kliky";

sleep 13; 

p3 say3D "pushupgrunt";

sleep 20;

};

This is the script I use, I grabbed parts of it from someone else's mission, can't remember which. Anyway, the script works, I just don't understand the _guy thing.

I thought _guy was just a random name picked for the variable defined at the beginning of the script? But if I try to change both instances of _guy to something else, a name of my choosing, the script no longer works. As it is, it works fine.

p3 is just the name of the unit, btw.

EDIT: Sorry, changing the name of the _guy variable worked now, I don't know why it didn't earlier, must've done something else wrong.

So when this script is called from my unit, which unit name is actually p3, is this unit now referred to as _guy? Is that it's name? I shouldn't use the same name in the script as the unit's name in the editor? (p3) So _guy should also be p3 instead?

Also, can I use the same variable name, for instance _guy, in scripts for other units, or must it be a different name for each unit/script?

Also, could someone explain exactly what everything above "while {alive_guy} do" does? Everything below including the while statement I understand.

I'm also a bit confused about what "this" and "null" means, when calling a script using execVM from the Init field of a unit, and when I should use "null" and when "this".

I meant to post this in the Arma 2 editing section, move please?

Edited by breyz

Share this post


Link to post
Share on other sites

if (!isserver) exitWith {};     //abort script if executed anywhere, but on server (in MP)
private ["_guy","_delay"];      //limit the scope of _guy and _delay variables to this script
_guy = _this select 0;          //_guy = first argument from script call
_delay = _this select 1;         //_delay = second argument from script call

sleep _delay;                   //do nothing for _delay seconds

Use the wiki, it's all there. :)

http://community.bistudio.com/wiki/execVM

http://community.bistudio.com/wiki/this

http://community.bistudio.com/wiki/Variables#Local_Variables

http://community.bistudio.com/wiki/private

Share this post


Link to post
Share on other sites

_guy = _this select 0;

_delay = _this select 1;

If you call that above script like this :

_nul = [p3, 60] execVM "script.sqf"

Then,

_guy = p3

_delay = 60

_this = [p3, 60]

_nul means nothing returned by the script will be stored.

If you put , variable1 = [] execVM "script.sqf" and script.sqf returns something.

That value will be stored in variable1, if script.sqf returns nothing,

variable1 will stored the path of the script (if i remember correctly)

The underscore infrontof _guy means it can only be used in that script.

You cannot do : _guy setdammage 1 in the editor or anywhere else.

But scripts called by the script.sqf can access _guy.

I mean if you have :

script.sqf where

_guy = "This is a guy"
[] exec "script2.sqf"

script2.sqf

_guy = "This is not a guy"

Then the value of _guy in script1.sqf will be immediately changed to "This is not a guy", because it can be accessed by the child script (script2.sqf)

To prevent this, you use private

private ["_guy"] at the start of script1.sqf

(This way, the _guy variable in script1.sqf and that _guy in script2.sqf will be different.)

And _guy works as a reference for the soldier you've put.

So if you execute the same script on p1,p2,p3. Three instances of the script will be running, first one's _guy is p1, second one's p2 and so on.

(The _guy's will no conflict either)

So if you want 10 soldiers to salute you. You just write this :

salute.sqf

private ["_guy"]
_guy = _this select 0
_guy action ["Salute",player]

And execute it on all the 10 soldiers with this line of code in their init box :

_nul = [this] execVM "salute.sqf"

(the "this" here refers to the object of the init box.)

(Note : there might be some facts missing, but I am just explaining you as clear as possible.)

Regards,

Haroon1992

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  

×