Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name: Password:
Ambiera Forum > CopperCube > Help with CopperCube
Is there any list of polyfills for es3?
Author Text

Guest
Guest
Quote
2022-11-03 09:06:39

I'm need polyfills for setTimeout (for non-block thread) and other, where I can find it?


okeoke
Registered User
Quote
2022-11-03 12:48:06

Hi,

setTimeout is technically not a part of JS specification. It's a part of window object, which is in its turn a part of browser. Or a part of node js api in case you're using node:)

There is an action called "doLater" which you can download here. It's not exactly setTimeout, but it allows you to run the delayed action.
https://www.ambiera.com/coppercube/download_extensions.html

I believe, the exact implementation would be sort of specific, since you probably also would like to pass the node object as a part of delayed function context. Basically, I guess, the idea is to create a global object/array which will store all delayed function calls along with the time they should be executed. On calling setTimeout you add these to the array. Then you register onframe event which takes current time, goes through the array and checks which of the actions can be already executed, executes them, and removes from the array.

For more polyfills you can check npm, which is a great source for any type of js code. For ex,:
https://github.com/NeilFraser/JS-Polyfills

I'll probably can check how this could be implemented tonight, in case you haven't find the answer by the time.


okeoke
Registered User
Quote
2022-11-03 16:32:48

Ok, this seems to work:
var timers = [];

// define setTimeout
function setTimeout(fn, ms, args) {
var executeAt = (new Date()).getTime() + ms;
timers.push({
fn: function () {
return fn.apply(this, args);
},
executeAt: executeAt
});
}

// register onFrameEvent which checks for
// the functions which should be called
ccbRegisterOnFrameEvent(function () {
var now = (new Date()).getTime();
for (var i = 0; i < timers.length; i++) {
if (timers[i].executeAt <= now) {
timers[i].fn();
// This array remove method is slow for small arrays
// but I guess you can get OutOfMemory otherwise
timers.splice(i, 1);
}
}
});


Setup example: https://drive.google.com/file/d/...

Notice, that if you need to pass any data you should use args arguments for that - it should be an array. I also didn't test what will happen in case you're not providing it, so if it doesn't work just put empty array there.

Usage example would be:
var node = ccbGetCurrentNode();

setTimeout(function(node, text) {
ccbSetSceneNodeProperty(node, 'Text', text);
}, 1500, [node, 'a text from the script']);



Guest
Guest
Quote
2022-11-03 20:05:32

thank you for answer, i'm tried your code.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internationa?" (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© 2020 Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact