Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
If you have ever needed the javascript code to run a variable amount of time delay this is it. 'wait' is the variable in ms containing the amount of delay required. You run the function with a simple "Delay(wait);" // time delay var Delay = function Wait(timeMs) { var me = this; this.registeredFunction = function() { me.doLaterFuncM(); }; ccbRegisterOnFrameEvent(me.registeredFunction); this.startTime = (new Date()).getTime(); this.endTime = this.startTime + timeMs; } function doLaterFuncM() { var nowM = (new Date()).getTime(); if (nowM > this.endTime) { ...add code needed here to run when done ccbUnregisterOnFrameEvent(this.registeredFunction); return true; }} Delay(wait); } |
||||
|
Lol I am trying to change a variable after 1 second, what's wrong here? var timer = 0; |
||||
|
I would leave the start as is - " var Delay = function Wait(timeMs) {" -dont put a number in there. |
||||
|
oh I see, This is the downloadable do later editor script which I know and have and use. But I 'm looking for a solution outside the editor and into an external JS text file... |
||||
|
You can create an extension with this: // This is a scripted coppercube action. // It does an action after variable 'delay' received else no delay /* <action jsname="action_DoLaterVar" description="Do later with variable delay"> <property name="ActionToDo" type="action" /> </action> */ action_DoLaterVar = function(){}; action_DoLaterVar.prototype.execute = function(currentNode) { var me = this; this.wait = ccbGetCopperCubeVariable("delay"); this.registeredFunction = function() { me.variableWait(); }; ccbRegisterOnFrameEvent(me.registeredFunction); this.startTime = (new Date()).getTime(); this.endTime = this.startTime-(-this.wait); this.currentNode = currentNode; } action_DoLaterVar.prototype.variableWait = function() { var now = (new Date()).getTime(); if (now > this.endTime) { ccbInvokeAction(this.ActionToDo, this.currentNode); ccbUnregisterOnFrameEvent(this.registeredFunction); }} |
|