geekm0nkey 144 Report post Posted March 2, 2018 (edited) Ok, need to know if this can be done,or is even proper to do... (FYI, don't want multiple files... so bare with me) //code for the call ["stackname", "onPlayerConnected", {[_id,_name,_uid] call FN_mycall}] call BIS_fnc_addStackedEventHandler; while {true} do { { // do work! } forEach allPlayers; FN_mycall = { _id = _this select 0; _name = _this select 1; _uid = _this select 2; // do something here }; FN_myothercall = { // do something else }; }; Edited March 2, 2018 by geekm0nkey Share this post Link to post Share on other sites
WolfkillArcadia 758 Report post Posted March 2, 2018 The code you posted does the following: Creates an onPlayerConnected EH with stackname and will call FN_mycall with those parameters. Infinitely do the following: Loop through allPlayers Assign some code to a global variable named FN_mycall Assign some code to a global variable named FN_myothercall I am confused on exactly what you are trying to do, but based on the title of the topic, all you want to do is call a function from a loop? // Always define functions before you plan on using them. FN_mycall = { _id = _this select 0; _name = _this select 1; _uid = _this select 2; // do something here }; FN_myothercall = { // do something else }; // Make sure to change "stackname" to something a little more... unique. ["stackname", "onPlayerConnected", {[_id,_name,_uid] call FN_mycall}] call BIS_fnc_addStackedEventHandler; // In an unscheduled environment, this will only loop 10,000 times before exiting. // In a scheduled environment, this will loop infinitely. while {true} do { { // do work! } forEach allPlayers; // You cannot call FN_mycall from here unless you define it's parameters // Call function FN_myothercall call FN_myothercall; }; 1 Share this post Link to post Share on other sites
geekm0nkey 144 Report post Posted March 2, 2018 (edited) Cool exactly what I wanted to know. Yes, my example was VERY simplistic just to get the idea across, the main while do loop is on a 5 minute uisleep delay between loops. Now you mentioned that my function variables are global is that because i didn't precede them with '_' such as _FN_myfunction or because i didn't do a private["","",""]; line defining all the variables? in the grand scheme of things is that bad? its simple enough to rename them or declare them. I'm pretty sure I want to contain them with in the scripts scope. Edit: purpose... perform the actions within the loop, but also look for the onconnected event and do that while the loop is asleep. And thank you. Edited March 2, 2018 by geekm0nkey Share this post Link to post Share on other sites
WolfkillArcadia 758 Report post Posted March 2, 2018 Yes, they are global because you did not have an underscore in front of the variable name. GlobalVariable _privateVariable private _localVariable Would be comparable to: Public, Class level variable Private, Class level variable Local Method variable If you work in other programming languages. There are a few differences between _privateVariable and private _localVariable. The one you will run into is that if you have a bunch of inline functions defined, like you do in your examples, you will end up sharing variables across those functions; essentially those variables being used at the script level instead of locally. Using private or private ["_localVariable"], will ensure that the variable is local to that scope. https://community.bistudio.com/wiki/private If you do not plan on using a function outside a script, I suggest declaring them as private local variables. If you plan on using them outside this script, you will have to define them as global. Especially in the case of the EH, as that FN_mycall will be called at a later date outside the scope of your script. Also, if you are feeling adventurous, I'd suggest looking into the threading system within Exile instead of using while loops. This is not required though. You can do a search across the files for examples on how to use it. ExileClient_system_thread_addTaskExileServer_system_thread_addTask Share this post Link to post Share on other sites
geekm0nkey 144 Report post Posted March 2, 2018 (edited) Again thank you for the information.. Here is a copy of the actual script i'm working with. Any improvements will be appreciated. Its an updated version of the pvpmarkers script i released earlier.. I needed to add the ability to capture players who connect and disconnect faster than the 5 minute sleep allowed.. So the ideal flow of this script is as follows.. I am certain this needs optimizing and correction. launch check for any players, create markers as defined in script sleep while sleeping have the ability to add or remove players markers if new player connects/disconnects on loop, update existing markers as defined. repeat. Update: I updated the code below, I read up on the use of private declares. I think I have it right? first two are for the entire script, the ones for each function and loop have been declared to prevent bleed over from the other areas of the script? correct. The function variables are not declared as I need them global for the EH to be able to reference them.. Are there any security concerns i should have? All has been resolved, and moved to the release page. Thank you for the guidance.. Edited March 3, 2018 by geekm0nkey Share this post Link to post Share on other sites