Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Cloned Node Detection

Zoo
Guest
Quote
2019-07-06 23:42:20

Hi All.

I am trying to clone a node, I seem to clone it successfully, however I then want the script to check if the node has been cloned.

I tried:

var s = ccbGetSceneNodeFromName(name_of_new_node);

if (s) print("found node.\n");
else
print("not found the node.\n")

But it never detects the new node.

I am using this script to clone the node

var sourceNode = ccbGetSceneNodeFromName("myNode");
var newscenenode = ccbCloneSceneNode(sourceNode);


Robo
Guest
Quote
2019-09-08 17:00:42

I just finished an epic workaround with this exact topic successfully.

You need to change the name of the new cloned object so it wont get lumped together with the original object. The default will have 2 objects with the exact same name. (some have said it will separate this by itself but not from my experience).

I add a number at the end each time and just record that as a CC variable.

To check and see what child nodes have been created run this code: (I have all my items inside a folder called "Loot")

var node = ccbGetSceneNodeFromName("Loot");
var count = ccbGetSceneNodeChildCount(node);
for(var i=0; i<count; i++) {
var child = ccbGetChildSceneNode(node, i);
print("node:" + ccbGetSceneNodeProperty(child, "Name") + "\n");
}


Robo
Guest
Quote
2019-09-08 17:11:35

Zoo wrote:
Hi All.

I am trying to clone a node, I seem to clone it successfully, however I then want the script to check if the node has been cloned.

I tried:

var s = ccbGetSceneNodeFromName(name_of_new_node);

if (s) print("found node.\n");
else
print("not found the node.\n")

But it never detects the new node.

I am using this script to clone the node

var sourceNode = ccbGetSceneNodeFromName("myNode");
var newscenenode = ccbCloneSceneNode(sourceNode);


This is my code to populate my game with cloned object - saved with position & rotation (7 items in the array per object, name, pos & rot):

var len = invVol.length; //my array for world objects
var nu = ccbGetCopperCubeVariable("cloneNu");

for (var i=0; i<len; i=i+7) {
var item = invVol[i];
var pos = invVol[i+1] +","+ invVol[i+2] + "," + invVol[i+3];
var rot = invVol[i+4] +","+ invVol[i+5] +","+ invVol[i+6];
nu++;
var newName = item + nu;
var node = ccbGetSceneNodeFromName(item);
var clone = ccbCloneSceneNode(node);
ccbSetSceneNodeProperty(clone, "Name", newName);
ccbSetSceneNodeProperty(clone, "Position", pos);
ccbSetSceneNodeProperty(clone, "Rotation", rot);
ccbSetSceneNodeProperty(clone, "Visible", true);
}
ccbSetCopperCubeVariable("cloneNu", nu);


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