Jump to content
Sign in to follow this  
hunne

local vs global variables vs me

Recommended Posts

Hi guys,

 

 

thought I´d be fiddling around with the "new" editor a while (last time I checked there was no eden editor) and got stuck with the syntax sort of...lack of basics too, I guess, been a long time...but there´s nowhere to start from somehow, so I just threw myself in...

 

I got a trigger with this as condition (heli drop-off): 

istouchingground r1 && r2 && r3 && r4;

the above is not working as intended...why? do I have to write it four times, or how do I querry each member of the group for it being on the ground? I know there is a more elegant way...

 

on activation I wanted to give "r1" a new waypoint or at least make him move to an object or some coordinates (to which I have no clue how to achieve that, the logic in most commands to me is flawed to say the least ("0 = moveinany unitname" for example) or I did not yet find said command e.g. "unit" moveto "coords in XYZ" or something) with the others following him automatically

"r1" moveTo [position player,0];

tried a lot of different combinations of ""()[] etc. - none of which is working since I get an error saying it is expecting not a string but an object or some times it is babbling about local variables in global some something (forgot it already ;) )...

 

I wanted to do this all inside the editor without having external files, this is really driving me mad already but it can´t be that hard, now can it?

 

Sure, I most likely could do this more easily, using waypoints which get activated by a trigger BUT what good are those commands to me then?

I simply want this to work the way I had in mind...for times when waypoints and triggers just won´t do the trick anymore^^

 

so any advice, (standard) code snippets etc., all is welcome :)

Share this post


Link to post
Share on other sites
Guest

Hey,

isTouchingGround only accept an object as an argument so you must repeat it 4 times (assuming your rX are objects/units).

You can use tye addWaypoint command btw if the others does not work.

Share this post


Link to post
Share on other sites

You need to realise that there are quite a few different data types in Arma and not every command works with any type. To know what types a command accepts you can always look it up on BIKI. For example you are trying to use STRING with https://community.bistudio.com/wiki/moveTo while it expects OBJECT. Also position is already an ARRAY of 2 or 3, there is no need to include it in another array like you did. Your .rpt file will show all the incorrect usage of types or other errors, so do not hesitate to check it.

Share this post


Link to post
Share on other sites

thx guys,

 

 

however, putting it four times = error...so...huh? 

I am switching like a mad man to the command list, look up every example if present and still don´t get it to work while, I think, doing exactly what is written in the example, well moveto does not have one, but it states it requires object and position, so again: huh? I tried using an array for position, like [50, 100, 0]; but again, it says it is a string where it expects an object and the object would be unit "r1" as I named the unit r1 (a global variable?) or is it _r1 (as local variable?)? Do I have to declare those first and if so, how?

 

also tried addwaypoint using a marker to get the position for the new waypoint, but since the above does not work I have no idea if what I wrote will work...guess not  :wacko:

 

anyways, gotta go to work now, will fiddle again later^^

Share this post


Link to post
Share on other sites

thx guys,

 

 

however, putting it four times = error...so...huh? 

I am switching like a mad man to the command list, look up every example if present and still don´t get it to work while, I think, doing exactly what is written in the example, well moveto does not have one, but it states it requires object and position, so again: huh? I tried using an array for position, like [50, 100, 0]; but again, it says it is a string where it expects an object and the object would be unit "r1" as I named the unit r1 (a global variable?) or is it _r1 (as local variable?)? Do I have to declare those first and if so, how?

 

also tried addwaypoint using a marker to get the position for the new waypoint, but since the above does not work I have no idea if what I wrote will work...guess not  :wacko:

 

anyways, gotta go to work now, will fiddle again later^^

 

You used this:

istouchingground r1 && r2 && r3 && r4;

correct would be this:

istouchingground r1 && istouchingground  r2 && istouchingground  r3 && istouchingground  r4;

more advanced:

{istouchingground _x} foreach [r1,r2,r3,r4]

Also try to stay away from simple naming conventions like in your example and get used to name your stuff using a custom tag like this:

"GOM_list_myIEDs"

could be "HUN_list_myIEDs" or "HUN_unit_r1", "HUN_unit_r2" in your case.

So it's less likely to cause problems when making missions using third party scripts/addOns

"r1" moveTo [position player,0];

would cause multiple problems like KK stated.

"r1" is a string

r1 would be the unit

and [position player,0] would look like this:

[[x,y,z],0].

 

Correct would be:

HUN_unit_r1 moveTo position player;

Cheers

Share this post


Link to post
Share on other sites

Quick comment:

{istouchingground _x} foreach [r1,r2,r3,r4]

would return true as long as 

isTouchingGround r4

 returns true.

 

It should look something like:

{isTouchingGround _x} count [r1,r2,r3,r4] == count [r1,r2,r3,r4]
  • Like 2

Share this post


Link to post
Share on other sites

This should also work:

{if (!istouchingground _x) exitWith {false}; true} forEach [r1,r2,r3,r4]

There are always many ways to do it, each with some tiny differences. Just make sure you get the syntax right.

  • Like 1

Share this post


Link to post
Share on other sites
Guest

any loop will always be slower than straight expression repeated several times

So

fnc_loop = { hint "test"; sleep 2; spawn fnc_loop };

Is faster than

while {true} do {hint " test"; sleep 2;}

And faster than

waitUntil ?

The real question is how to have the code as clean as possible but as efficient as possible ? You have to sacrifice the one or the other ?

Share this post


Link to post
Share on other sites

woah woah...geez guys...slow it down^^  :D

 

*writes down* istouching...

 

so, apart from loosing the "" I freakin had it...d-oh  :o

...bring out the BUTTON!

 

http://www.nooooooooooooooo.com/

 

and I had the stupid idea of putting more semicolons than needed...c´mon brain...you can do it!

 

@GOM: in [[x,y,z,]0], what does that zero stand for?

 

did I get it right, the _x in davidoss example is a local variable which gets replaced by r1 to r4 (which are global variables) and if all four return true (hence the count to 4) the condition is set to 4 = 4 and is therefore true?

If I wanted to reverse it, I´d put an ! in front of it? no, wait...that would return false whenever it is not four...

oh boy...me brains...

 

gotta eat something first, just got home from work

 

 

oh, maybe a small request in the meantime:

 

at what occasions do I use [], () and {}?

sorry if that is a rather stupid question in terms of RTFM, but I learn best using examples and a hands-on approach...leave them books to the librarian

 

anyways, thx so far...I´ll be back with more questions  :D

Share this post


Link to post
Share on other sites

Local variables are only visible in a specific script.

Global variables are visible on the whole computer where they are defined.

 

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

4 isEqualTo count ([r1,r2,r3,r4] select {!istouchingground _x})

returns true if all 4 units is not touching ground

 

and

4 isEqualTo count ([r1,r2,r3,r4] select {istouchingground _x})

returns true if all 4 units is  touching ground

Share this post


Link to post
Share on other sites

another question:

 

I wanted a  groups waypoint condition to be TRUE using something like

150 = trans1 distance APC > 150;

but that does not seem to work, do I really need a trigger and two waypoints?

Share this post


Link to post
Share on other sites

nope, doesn´t work either...but thx

hmm...guess I have to use a trigger then...ah ok...the expression gets true then the waypoint gets completed...well...that´s why...hmmm

 

ok, so I set the first WP to be "loiter" and set the WPcomplete condition to what was written above, the next to vehicle get in (along a check if everyone is on board) and the last to move and now nothing is happening at all, do I need to to set the next WP to be valid in the onactivation tab?

Share this post


Link to post
Share on other sites

So

fnc_loop = { hint "test"; sleep 2; spawn fnc_loop };

Is faster than

while {true} do {hint " test"; sleep 2;}

And faster than

waitUntil ?

The real question is how to have the code as clean as possible but as efficient as possible ? You have to sacrifice the one or the other ?

No idea what you just said.

command;

command;

command;

command;

command;

will be faster than

for ...1 to 5.. {command;}

Share this post


Link to post
Share on other sites

why are those stupid civilians not boarding the darned truck and flip off? I cant get a single civ to enter a vehicle by using simple waypoints even without using scripts and code...WTF is that bull?

Share this post


Link to post
Share on other sites
Guest

No idea what you just said.

command;

command;

command;

command;

command;

will be faster than

for ...1 to 5.. {command;}

I was talking about loops.

You said that any loop will be slower than an expression ran multiple time so. If you want to do a loop, is it faster to recall the function at its end or a while / for loop ? Does messing around with the scheduler is more efficient than while / for loops ? If so just why ? That does not seems logic at all compared to c++ for exemple. My other question is, is it better to have a clean code or a faster code then. In most of the languages having a clean code often means the code is faster.

Share this post


Link to post
Share on other sites

what kind of waypoints ?

 

 

uhm well, the usual ones, placed with right mouse + shift

 

first one is move, then get in vehicle and then move again

Share this post


Link to post
Share on other sites
4 isEqualTo count ([r1,r2,r3,r4] select {!istouchingground _x})

Instead of r1,r2,r3,4 and so on, try to use TAG_r1,TAG_r2.... where TAG could be your name for example.

 

Because you never know if a mod already uses a variable name like that. It add some additional safety.

Share this post


Link to post
Share on other sites

I was talking about loops.

Me too. for loop, forEach loop, count, select, apply etc. all will be slower as there is overhead with loop handling.

Share this post


Link to post
Share on other sites
Guest

Me too. for loop, forEach loop, count, select, apply etc. all will be slower as there is overhead with loop handling.

 

I'll send you a pm, let's keep this thread clean now.

Share this post


Link to post
Share on other sites

ok guys, so I got my mission going mostly smooth now - after finding out that placing 5k mines is not so very good in terms of fps ^^, but I do have a question about triggers: if I set those in the activation tab to "none" and then write something like 

taskcompleted tsk2;

in the condition field and then sync this trigger to an settaskstate object (<assign tsk3> after having created it), does that work properly or do I have to sync or set owner status of the settask thingie with something else, cuz I have a total of five tasks and only the first and second one get autoassigned as I enter a trigger which is set to opfor-present (or with condition: player in thislist; also tried "anyone-present" with that and "none" too), the third does show up in the menue and after completing that it does progress as planed mission-wise but the last two tasks don´t get assigned and don´t show up at all and I really checked what I synced etc., so I think it might be something with those triggers, since tsk3 get´s triggered by the demise of three objects (getting task complete and all up until that point) and the other two are just conditioned to the above taskcompleted tsk x-1...

 

thought I asked before I start setting it up from scratch  :lol:

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  

×