Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Announcements and Showcase
New extension - variable time delay

Robo
Guest
Quote
2020-05-15 08:05:48

I edited the doLater extension to allow for any amount of time delay to be run as needed based off coppercube variable ('delay').

Its helped tidy up my javascript into neat sections this way.

// This is a scripted coppercube action.
// It does an action after variable 'delay' received

/*
<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;
var wait = ccbGetCopperCubeVariable("delay");
this.registeredFunction = function()
{ me.variableWait();
};

ccbRegisterOnFrameEvent(me.registeredFunction);
this.startTime = (new Date()).getTime();
this.endTime = this.startTime-(-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);
}
}


creaturefreak
Registered User
Quote
2020-05-22 23:20:32

Hey Robo, thanks for the code

quick question...how does this extension exactly work? can you explain a scenario or example where you would use this?

thanks

CF


Robo
Guest
Quote
2020-05-23 00:09:27

All you have to do is create a variable called 'delay' and give it a value in milliseconds to match the time delay you want for a once off time delay action.

Its an action extension that you need to create - just copy and paste the above and change name to 'action_DoLaterVar'.

The delay variable must be setup before running this action.
Reload and verify extensions inside CC and you then have this in the list that can be selected as an available action.

Why have this ? - I needed this a few times when playing different music tracks with different lengths or when I needed to play different sound effects with different lengths depending on size of container being opened, and once played do something afterwards.

Stay tuned to next video coming soon - will show this off in the video..


creaturefreak
Registered User
Quote
2020-05-25 22:15:37

Robo wrote:
All you have to do is create a variable called 'delay' and give it a value in milliseconds to match the time delay you want for a once off time delay action.

Its an action extension that you need to create - just copy and paste the above and change name to 'action_DoLaterVar'.


Thanks bunches, Robo! we appreciate your knowledge and contributions. Going to try this out!

best,

CF


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "In?ernational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact