Jump to content
Sign in to follow this  
lawndartleo

Can somebody 'splain to me...

Recommended Posts

... in terms that an absolute novice can understand, or point me at documentation that will do the same.

This page reads like Greek to me...

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

I am probably just being dense and once it hits me I'll get it, but right now I just don't. It's been 20+ years ince I took a Fortran77 class in college and I remember NOTHING.

When/why do I use the "_" character. Global and local variables mean NOTHING to me at the moment.

 
_var = something

var = something

and when " " needs to be used... or not

 
_smoker = "SmokeShellGreen" createVehicle (getMarkerPos "asloc");

when I have

 
_asloc = getMarkerPos "asloc";

why cant I use

 
_smoker = "SmokeShellGreen" createVehicle (getMarkerPos _asloc);

Edited by lawndartleo

Share this post


Link to post
Share on other sites

Firstly the '_' defines a local variable, which means it is local to the scope it was created in (I think anyway ^^), and so you can have two scripts with two values for a local variable and they wont interfere with each other. Example:

_unit = _this select 0; //_unit becomes the first parameter passed to the script or function
_unitType = typeOf _unit; //Unit classname

If you have two of those scripts where _unit has been given a different parameter then they can work along side each other without much problem, however if you used a global variable (no underscore) it would get overwritten by whichever value was put last.

As for the " " marks, they denote a STRING, which is a chain of letters, number or symbols. These are usually used for writing text onto the screen (such as when using the hint command).

In your example:

when I have

Code:

_asloc = getMarkerPos "asloc";

why cant I use

Code:

_smoker = "SmokeShellGreen" createVehicle (getMarkerPos _asloc);

You have made _asloc the POSITION of the marker, you then go on to try and get the Position of a position (see what you did wrong?), which doesnt work, the right was would have been to use (I think....again :P ):

_smoker = "SmokeShellGreen" createVehicle (_asloc);

Share this post


Link to post
Share on other sites

When/why do I use the "_" character. Global and local variables mean NOTHING to me at the moment.

Underscore is used for local variables. Simply said, local variables are only accessible in that one script you define them.

That means if you define a local variable _something in a script file "test1.sqf" you won't be able to access it later from script "test2.sqf".

and when " " needs to be used... or not

Quotation marks are used to wrap strings (simply said text).

when I have

 
_asloc = getMarkerPos "asloc";

why cant I use

 
_smoker = "SmokeShellGreen" createVehicle (getMarkerPos _asloc);

getMarkerPosition will return a marker's position as the name suggests. In your example you first store the position in a variable and then later attempt to get a position from that position again. I believe this is what you're trying to achieve:

_asloc = getMarkerPos "asloc";
_smoker = "SmokeShellGreen" createVehicle _asloc;

A world of advice on createVehicle too, the command creates the objects (vehicles) "safely" - ensures they don't collide with other objects. What this means in practice is the objects do no appear exactly on the position you specified. For this to happen you have to setPos the object once it has been created. An example for your code above:

_asloc = getMarkerPos "asloc";
_smoker = "SmokeShellGreen" createVehicle _asloc;
_smoker setPos _asloc;

EDIT: I see I'm a bit late here.

Share this post


Link to post
Share on other sites

My head hurts.

So in joe.sqf I can use

 
_var

and in fred.sqf I can use the same

 
_var

but they will not be the same thing.

So if I want joe to pass fred the same var, that brings in the whole

 
nul = [ something here to pass ] execvm "fred.sqf"

thing up. How do I pass _var from joe to fred? Somewhere in fred sqf I have to have

 
var = _var

or

 
_var = var

???

Which stil leaves me scratching my head about this bit of code that works great

g1wp1=_grp1 addWaypoint [_asloc, 75];
g1wp1 setWaypointBehaviour "COMBAT";
g1wp1 setWaypointType "LOAD";
[_grp1, 1] setWaypointStatements ["true", "landed = true"];
// pop smoke at lz
waituntil {(1000 - (random 500)) > _man distance _AShelo1};
_man playAction "ThrowGrenade";
sleep 5;
_smoker = "SmokeShellGreen" createVehicle (getMarkerPos "asloc");

The waypoint was created from _asloc but the green smoke that the guy pops needed me to use "asloc".... in the blasted " " marks.

Aaaaaaaagh!

Edited by lawndartleo

Share this post


Link to post
Share on other sites

_asloc is a local variable that holds the three point position array of the marker. So you dont need getmarkerpos _asloc

just _asloc.

_smoker = "SmokeShellGreen" createVehicle _asloc;

you use getmarkerpos "asloc" to generate the array in the same line of code and the result is the same so its up to you how you want to use position arrays.

Either getpos/getmarkerpos something and save it in a variable as in the example below, or use the getmarkerpos in the same line of code.

If you had two scripts moving the marker around somehow you would likely just use getmarkerpos "markername" instead of recording a variable just to make sure you have the exact position.

If you read the Comref and look at examples of commands you can see how they are used. Anyone who wants to script Arma2 should read the entire COMREF from end to end. It will help you out and save the need for basic questions and get you to more advanced things sooner.

Please use descriptive thread titles in the future. Look at all the other titles in here and notice how they describe the problem in the title and not "I have a question". "Noob needs help" etc. (well for the most part) This goes for all the new users around here. Pretty Please?

Share this post


Link to post
Share on other sites

(getMarkerPos "asloc") = _asloc....

Hmmm, did a light just go on? I think it did!

(getMarkerPos "asloc") fetches and array where _asloc is already an array.

P.S... the links in your sig intrigued me but they are broken... perhaps they are dead (apparently FP85 related)... or maybe not. Scripting the aviation part of ARMA is what I am most interested in.

Share this post


Link to post
Share on other sites

Local variables are useful for scripts that might be run more than once. For example I might like to spawn a lot of objects that generate smoke. For each smoke generator I run a script. I can run lots of instances of that script, and each one relates to a different smoke generator.

In this script, there might be a variable called "_thisPosition", which hold the coordinates of that smoke generator. Obviously each script will have different values, but internally they are all called the same. It means I can use the same script hundreds of times in one game, and they'll all make smoke in different places according to _thisPosition.

It's a bit like having a person called David in every house in your street. Whatever house you go to, you can "access" David :) and each will have his own attributes.

Share this post


Link to post
Share on other sites

It's a bit like having a person called David in every house in your street. Whatever house you go to, you can "access" David :) .

Just make sure you use the backdoor!:yay:

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  

×