Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Cloning and re-naming node in WebGL

srfstudio
Registered User
Quote
2019-07-17 01:53:05

...I must be doing something wrong or the node-renaming after cloning is not working in WebGL :(

This works as it should in Windows...
var SourceNode = ccbGetSceneNodeFromName("NodeToClone");
var ClonedNode = ccbCloneSceneNode(SourceNode );
ccbSetSceneNodeProperty(ClonedNode, "Name", "NewName");
("NewName" is a var that's being incremented by 1 each time before another node is cloned)
...also this works great in Windows:
var SourceNode = ccbGetSceneNodeFromName("NodeToClone");
var ClonedNode = ccbSetSceneNodeProperty(ccbCloneSceneNode(SourceNode ), "Name", "NewName");
None of these work in WebGL at the moment of cloning. I can re-name node after cloning (with on-click action) but not in the moment/same pass as it's being cloned. It doesn't even adds number after the name, it just duplicates original-node name. That completely breaks WebGL version of my game :(
Does anyone knows of any possible solution for this?


srfstudio
Registered User
Quote
2019-07-17 17:42:59

...so after two days I've finally figured it out: After cloning a node Windows build is changing node-references (like "this.MyNode") both in CC native scripts and in my custom scripts. WebGL build is changing ONLY native script references, not custom/user!
So after I've changed all of the "this.MyNode" references with "node" or "currentnode" in my scripts things started to function :)

Also my increment-var-number that I used for separating cloned names that worked in Windows build was this:
var nameadd_var = ccbGetCopperCubeVariable("nameadd");
var nameadd_value = nameadd_var + 1;
var newname = "enemy" + nameadd_value;
ccbSetCopperCubeVariable("nameadd", nameadd_value);
...but in order to work in WebGL I needed to code it like this:
var nameadd_var = ccbGetCopperCubeVariable("nameadd");
var nameadd_value = Number(nameadd_var + 1);
var newname = "enemy" + nameadd_value;
ccbSetCopperCubeVariable("nameadd", nameadd_value);
Now number works in both Win & WebGL builds.

So if anyone is targeting both Win & WebGL and has cloning of nodes with script-references like "this.MyNode"/"this.NodeName"/"this.Me": Use only "node" or "currentnode" references in your scripts.


Zoo
Guest
Quote
2019-07-18 22:31:57

This is the exact script that I was looking for a few weeks ago.

Fantastic work!


srfstudio
Registered User
Quote
2019-07-19 18:38:02

Cheers, I'm glad someone else also found it useful.
I never expected Windows & WebGL versions to have this kind of differences when it comes to code. In Windows builds all node-references in custom scripts that are references to the node itself get 'overwritten' with a new node-name when cloned. WebGL doesn't seem to do that, they all have to be 'node' or "currentnode", depending on what's specified inside a function brackets.


create0
Registered User
Quote
2019-07-20 18:20:33

Thank you so much for providing truly an informative knowledge. I am glad to know about it.


srfstudio
Registered User
Quote
2019-07-22 12:27:04

You're welcome, it's always good to know that something you do can also be a benefit to others. Cheers!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (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