Jump to content
ROGER_BALL

How many times does my execVM *.sqf run inside init.sqf

Recommended Posts

I have always been able to self-teach just about any language I wanted over my life but I have to say, this ARMA3/SQF combination has seriously Kicked.M.A.  I venture to wager that I have encountered the simple answer to this question without understanding the cryptic definitions and conventions.  I must surrender at this point and just come here to indulge someone's good graces and thank you in advance. Maybe I'm just getting old.  😕

 

Anyway, my logs show perhaps 2,000 hours or so doing mission designs and I  muddle through but this is a brick wall for some reason. Quite simply, I have an init.sqf that contains

 

execVM "respawnMKR_INDEP.sqf";

 

This sqf contains the following code:

 

while {true} do {

_pos = [INDEP_Roger_Ball, 1, 50, 3, 0, 20, 0] call BIS_fnc_findSafePos; 

"respawn_guerrila" setmarkerpos _pos; 

sleep 5;

};

 

My question is:  Other than the one time that the init.sqf runs, does this code ever run again if I never "call" it or otherwise refer to this .sqf file?  My understanding is that it only runs once. May I assume that "while {1}" will never fail and the execVM initiates this "5-sec" loop ?  I conclude this from seeing a moving "respawn_guerrila" marker on the map.  This blows my simple mind to have a loop in my code. That's something I have avoided in past lives and thus I ask these questions because it seems a waste of resources. Maybe not.  If my assumptions are correct, and since the moving respawn position is only used when I die, would it make sense for me to figure out a way to just keep track of the _pos without doing anything until I die and actually need a "safe _pos"? Perhaps there is negligible differences in the two ideas. The BIS function may be small or may be huge - I donno the overhead in this new world I find myself loving - and I really do obsess over ARMA3 and envy the worlds of young, quick and skillful minds. My missions would really take on a different life. But, I digress. 

 

Third, even with good parameters feeding this BIS_fnc_findSafePos function, it still puts me into the water/ocean or some other weird location - but I am not asking for that to be addressed here until I exhaust the huge data mine that exists on this topic. I can hold my own with coding electronic interfaces in C+ but this is a whole different world. My hat is off to the many experts I lean on here for ideas and advice.  Thanks for your time to comment briefly from your expertise.

 

Thanks.

 

 

Edited by ROGER_BALL
Clarity and grammar

Share this post


Link to post
Share on other sites
11 minutes ago, ROGER_BALL said:

Other than the one time that the init.sqf runs, does this code ever run again if I never "call" it or otherwise refer to this .sqf file?

Nope. It only runs once on mission start, see https://community.bistudio.com/wiki/Event_Scripts. What's important to note is that it will be executed for the server and all clients, which, in your case, is redundant. Only the server should move the marker as setMarkerPos is a command with global effect (everyone sees the change).

11 minutes ago, ROGER_BALL said:

My understanding is that it only runs once and a "handle" is generated (whatever that does for me, I don't know).

A handle is used to refer to the script. It's used in commands like terminate and scriptDone, see https://community.bistudio.com/wiki/Script_Handle

 

13 minutes ago, ROGER_BALL said:

But, what makes me wonder is that this code seems to execute every 5 secs as evidenced by the moving "respawn_guerrila" marker on the map. 

Just as it should?

  • Like 1

Share this post


Link to post
Share on other sites
33 minutes ago, 7erra said:

Nope. It only runs once on mission start, see https://community.bistudio.com/wiki/Event_Scripts. What's important to note is that it will be executed for the server and all clients, which, in your case, is redundant. Only the server should move the marker as setMarkerPos is a command with global effect (everyone sees the change).

A handle is used to refer to the script. It's used in commands like terminate and scriptDone, see https://community.bistudio.com/wiki/Script_Handle

 

Just as it should?

 

Yeah, right? Since you put it that way 🙂 .. yeah, I guess that's the answer, isn't it. The init.sqf runs this other aforementioned .sqf which is just a infinite loop that runs every 5 seconds, moving the marker to my location at the moment.  So, then, I suppose that since I spend most of my time flying a helicopter, I will have to investigate what position data gets sampled just at the moments after being shot while flying. I have no idea if the BIS_fnc_findSafePos grabs the helicopter's 3D position data as it plummets or my dead body's 2D or 3D position data. I have much work to do before I can impose further. Thanks 7erra. Much appreciated my friend. 

  • Like 1

Share this post


Link to post
Share on other sites
10 hours ago, ROGER_BALL said:

This blows my simple mind to have a loop in my code. That's something I have avoided in past lives and thus I ask these questions because it seems a waste of resources. Maybe not.  If my assumptions are correct, and since the moving respawn position is only used when I die, would it make sense for me to figure out a way to just keep track of the _pos without doing anything until I die and actually need a "safe _pos"?

 

A loop in a code is no big deal if done right, it can be a big deal if done wrong.  They have so many uses and advantages, one purpose being that a loop serves as an update; this gets updated, and that gets updated, to keep things current.  And that's what your loop is doing, it's keeping the "respawn_guerrila" marker near the INDEP_Roger_Ball object.

 

But as you point out, a real question is whether the marker needs constant updating of its position.  You might instead consider using addEventHandler with a killed or mpkilled event handler (depending on whether SP or MP), to have the marker moved by the killed event, rather than a continuous loop.

  • Like 3

Share this post


Link to post
Share on other sites

Respawning is MP oriented because this functionality is not implemented in SP session (you can script a similar thing, handling damage instead of death, but it's not immediate).

After that, you can play as unique player/playable in MP session, generally hosted, so you'll notice no real difference between SP or single hosted MP, except for initialization order.

 

As @opusfmspol  wrote, each time you can use an event handler/ event script, use it.

The event handlers are usually more recent than event scripts. There are several types EH (basic), MPEH (for multiplayer), MEH (mission event handler), user action EH, Players' UI EH (interface)

 

The basic ones are numerous and sufficient most of the time. You must pay attention for their Arguments and Effects, like for any command/function in MP.

Most of the time, they are AG (argument global) but Effect local You just have to remember they will fire where they are, and the result will be local, if you apply it thru a local script and if you don't broadcast (remote execute) it. On the other hand, that doesn't hurt to run them everywhere (like in BI examples) and obtain the effects on each PC, independently.

Keep in mind, some of them are Global effect (so no need to run them everywhere), and/or Server Only for arguments (so to be run on server).

 

THE MPEH (so AG EG for MPHit and MPKilled, AG EL for MPRespawn) are very specific for these phases of the game, allowing a global argument, and global effect MPRespawn excepted, handy for runing them from a local script.

 

Use Mission EH, each time it's possible. No arguments, they run where they are scripted, so from init.sqf or initServer.sqf or initPlayerLocal.sqf.... It's handy.

Their effects stay local, so perfect for performance. They are complementary of EHs, and you'll find very useful MEHs like Draw3D, Map, MapSingleClick, Loaded, OnUserConnected, eachFrame... You can even script for damper the "terrific" eachFrame for performance saving...

 

I let you discover the player's action EHs and the UI EHs, for overriding actions or adding features along with key binding.

This list is not really exhaustive. There are more scripted events, waiting for specific event, like arsenal opened... Follow the links and sub-links.

 

 

 

 

 

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Great info and advice from all and, it is very much appreciated and helpful. Thank you for taking your time to share your expertise men. Check six.

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

×