Jump to content
Ed!

What happens to the local variables of a terminated script?

Recommended Posts

I've noticed that when playing short missions, most players disconnect because of excessive lobby wait times.

 

I now made an array which stores all my handles and when the mission is over, I terminate all these handles and just rerun my init.sqf.

 

Im just a bit concerned about the memory usage of the server after this action occured more than 10 times.

 

Will there be memory issues caused by this practice?

Share this post


Link to post
Share on other sites

Sounds like a waste of time to me.

 

There's already 2 or three threads on this topic in this forum if you care to do a search and read through them.

Share this post


Link to post
Share on other sites

Thank you for answering the question.

 

Edit:

I've searched. Found nothing.

You have no motivation for your statement. Thus, I can't gain insight from your inputs.

Share this post


Link to post
Share on other sites

Script terminates, variables terminate, memory is reopened (last I remember anyways).

  • Like 1

Share this post


Link to post
Share on other sites

Thank you for answering the question.

 

Edit:

I've searched. Found nothing.

You have no motivation for your statement. Thus, I can't gain insight from your inputs.

 

 

Whatever. 

 

Didn't take long to find this:

 

https://forums.bistudio.com/topic/162933-are-local-variables-destroyed-at-script-termination/?hl=local+variables

 

As JShock says, it frees up memory when it's done.

Share this post


Link to post
Share on other sites

If you're asking what I think then I'm saying it's a non-issue. 

 

Really the onus should be on you to demonstrate it is a problem, and upload a mission or demo for others to corroborate or dispute your findings.  If you want to spend the time and do that then go ahead, but I don't think there's a connection between local variables and "excessive lobby wait times" and therefore I think it's a waste of time.

  • Like 1

Share this post


Link to post
Share on other sites

If all you are trying to do with clear a variable from memory. Do this _var = nil or var = nil. Alright I think I'll explain this a bit better.

Local variables are existent within their scope. E.g a script say for example you have _myLocalVariable = 5; defined within the script technically, if you are using this as a function call with yourTag_fnc_someFunctionOrProceedure. When

IF A. Function executes and returns a value any locally defined _variables will become undefined as, the variable doesn't exist outside of the scope.

IF B. Procedure Executes and finishes, it's locally defined _variables will become undefined as the variable doesn't exist outside of the scope either.
Now if you wanted to pull a locally defined variable out of a Function you can define the function and get it to return values allowing you to take the variables defined inside
the function to become the variable of another instruction.

 

Satisfactory answer?

 

Example:
 

private ["_x1","_y1","_x2","_y2"];

_calculateSqrdDist = [_x1,_y1,x2,y2] call BIS_fnc_distanceSqr2D;
There is locally defined variables within the BIS function which returns a value which is the squared distance between point A and Point B.

Which you can re-assign as another locally defined variable within another script or a globally defined variable

var = _calculateSqrdDist;

_var = _calculateSqrdDist;

  • Like 1

Share this post


Link to post
Share on other sites

IF A. Function executes and returns a value any locally defined _variables will become undefined - if they do not already exist in the calling scope or were made private within the called function.
e.g

myFunction = {
	_myVar = 2;
}; 

_myVar = 1;
_myVar call myFunction;
hint str _myVar;
//Result = 2
myFunction = {
	private [ "_myVar" ];
	_myVar = 2;
}; 

_myVar = 1;
_myVar call myFunction;
hint str _myVar;
//Result = 1

I now made an array which stores all my handles and when the mission is over, I terminate all these handles and just rerun my init.sqf.

So are you saying that instead of ending a mission normally and going through debriefing, starting mission, picking units, seeing briefing, start.
You are instead resetting the mission while it is still active? by running the init.sqf?
I can not see a problem with this as long as your mission is mainly script based. There would be some things that would need resetting like player positions and deleting anything created during the mission and maybe some other caretaking needed like resetting modules etc.
In which case the only scripts you would need to terminate is anything spawned in a loop or spawned functions that maybe held open waiting for something.

If this isnt what you mean then i do not understand the correlation between Execsive lobby wait times and ending scripts.

  • Like 1

Share this post


Link to post
Share on other sites

I've noticed that when playing short missions, most players disconnect because of excessive lobby wait times.

 

I now made an array which stores all my handles and when the mission is over, I terminate all these handles and just rerun my init.sqf.

 

Im just a bit concerned about the memory usage of the server after this action occured more than 10 times.

 

Will there be memory issues caused by this practice?

 

Terminate is used to permanently destroy the action. If your using it in the init.sqf, then you'd probably rage quit.

 

 

Regarding Das Attorney's comments,

 

Its best if you made your action a function like the above posts. (and making it a separate .sqf rather than making it the init.sqf)

 

 

Then, in your init.sqf, put this in it:

call compile preprocessFile "action.sqf";

This way, you can use call to initiate your action. (if your have script suspension in the function, use spawn)

 

 

However, Das' link already had similar to your question. So please use the search function located at the top-right most part of the page.

  • Like 1

Share this post


Link to post
Share on other sites

So are you saying that instead of ending a mission normally and going through debriefing, starting mission, picking units, seeing briefing, start.

You are instead resetting the mission while it is still active? by running the init.sqf?

I can not see a problem with this as long as your mission is mainly script based. There would be some things that would need resetting like player positions and deleting anything created during the mission and maybe some other caretaking needed like resetting modules etc.

In which case the only scripts you would need to terminate is anything spawned in a loop or spawned functions that maybe held open waiting for something.

If this isnt what you mean then i do not understand the correlation between Execsive lobby wait times and ending scripts.

This is exactly the answer I was looking for. My whole mission is based on scripts - Nothing is staticly placed except the respawn location.

 

So what I did is terminate all the handles, then delete all the mission objects, set some important variables to nil and then execute the init.sqf again.

Thank you for all the replies. I am spamming the "like this" for all of you.  :P

Share this post


Link to post
Share on other sites

Variables are deleted without a trace. Anyway, you should not be using scripts to run code, you should be compiling your scripts using the built-in functions library. The only variables you need to worry about are global variables, but I doubt you'd be dynamically creating global variables (also you shouldn't).

  • Like 1

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

×