Are scripts single-instance?
Are scripts single-instance?
]]>
« Question to scripters: (Previous Post)
(Next Post) hey guys, i am pretty new to scripting and want to know if it is possible to use http://jsbin.com/ for… »
< ![CDATA[
I don’t think so.
I have a script with a timeout function after some seconds (they are considered part of the script itself, right? ). I launch the script from the tap function of an item, and I can have as much functions ‘waiting’ as I want (don’t know the limit if there is one)
]]>
< ![CDATA[
I have set a script to positionchanged event and build a check if already an instance is running. If yes write something to logfile. This never happens
]]>
< ![CDATA[
The position changed event is called when the previous one finish….I think.
Try to put it with timeout functions…maybe they work
]]>
< ![CDATA[
Somehow setTimeout seems to be just ignored… Everything is done instantly
]]>
< ![CDATA[
Well, depend on how are you checking it. I know some functions that returns the parameter they had when the script was launched, even if it is run minutes after with settimeout.
How are you checking it?
]]>
< ![CDATA[
var doIt=function()
{
LL.setScriptTag(parseInt(LL.getScriptTag())-1);
LL.writeToLogFile(LL.getScriptTag()+”\n”,true);
}
var tag=LL.getScriptTag()||null;
if(tag==null){
LL.writeToLogFile(“start\n”,false);
tag=”0″;
}
LL.setScriptTag(parseInt(tag)+1);
LL.writeToLogFile(LL.getScriptTag()+”\n”,true);
setTimeout(doIt(),1000);
]]>
< ![CDATA[
Hm, do it work if you launch it from a shortcut and you click it very fast?
Edit: the ‘or’ operator || in this sentence
Ll.getScriptTag() || default;
Is used to set a default value when the left part is null, so
LL.getScriptTag() || null;
Is exactly the same as
LL.getScriptTag()
😉
]]>
< ![CDATA[
I’ll try
]]>
< ![CDATA[
Still 0101010101010…
]]>
< ![CDATA[
Wait a moment
Of course it is not doing the timeout, because it takes a function, not the output of a function.
I mean:
setTimeout(dolt(),1000)
is evaluating the dolt function, and then the setTimeout is doing the output: null
You need
setTimeout(dolt,1000)
]]>
< ![CDATA[
Lukas Morawietz I finished editing my comments. Check them all (sorry for the editing)
]]>
< ![CDATA[
Scripts are run sequentially, one at a time but can possibly be interleaved if one is paused (a dialog box).
When setting a timeout, the function is called later and holds a reference on local variables, hence it is safe.
There isn’t really a notion of instance of a script. Instead there are data (possibly shared through the root object) and there is code execution. Code execution is always sequential, but may be run partly.
]]>