Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Use variable node ID's in behaviors? Get node ID?

potticus
Registered User
Quote
2016-10-02 00:27:31

Hi,

Eg; I dynamically create 100 cloned doors with 100 corresponding cloned door buttons, and I want to allow each door button to activate its corresponding door (eg; doorbutton37 opens door37).

I noticed that when you clone a node, its ID and any mention of its ID in its own behaviours automatically gets given a new name (1st clone of 'door' becomes door1, then door2, etc).

But this is no good, because all 100 doorbuttons will all still try to activate the original door only.

If variables could be used in behaviors then I could specify the exact door needed.

Alternatively, is there some javascript I can use to return the name of the node that is being interacted with?

Eg; If i know that doorbutton37 is being pressed, then i know to animate door37, and could easily do that with custom javascript, but do not know the command to get the name of the node.

If anyone can help or suggest a solution that would be awesome.

Many thanks


potticus
Registered User
Quote
2016-10-02 00:37:37

I know you can get the name of a node like this:

ccbGetSceneNodeProperty(sceneNode, Name)

But that only works if you know the name of the node in question to start with, so is a bit useless..

unless there is a $this variable or something that retrieves the node ID that the behaviour is attached too?


niko
Moderator
Quote
2016-10-02 05:54:48

Hm, I could think of a 'hack' to do that. Some actions have the property of doing their action with the 'current' node. In your 'when clicked' behavior, add such an action. Like setting the rotation or scale oft he 'current' node to some special value and then in your javascript, search for that node.


Remus
Guest
Quote
2016-10-02 09:02:45

You should stay away from behaviours.
Also, 100 behaviours for 100 objects is a bad move (and a waste of resources).
The best approach is a single function in the main timeline for all the 100 buttons.
All you have to do is to identify where the trigger came from (button number extracted from the object name)


potticus
Registered User
Quote
2016-10-02 19:45:05

Thanks guys,

Niko, interesting idea - when a button has been pressed, I could change the button's scale property (0.999 vs 0.998 or some other non-noticeable value) and then run a loop to find out which one has the different value, then when the loop finds the 0.998 value, I'll know what the node ID is by counting the loop number. A bit long winded, but could work.

Remus, I would still need to know how to simply get the current node ID, which is the real problem here. Unless someone knows example code for Getting this? Good point about resources and using a single function in startup code - I can implement that in conjunction with Niko's solution.

Cheers


potticus
Registered User
Quote
2016-10-13 00:10:23

I've spent many hours trying to get the above suggestion to work, and I'm nearly there, but I've hit a snag..

Basically, I can't seem to evaluate two node values:




var default_door = ccbGetSceneNodeFromName("door");
var default_door_scale = ccbGetSceneNodeProperty(default_door, "Scale");

var cloned_door = ccbGetSceneNodeFromName("door1");
var cloned_door_scale = ccbGetSceneNodeProperty(cloned_door, "Scale");

if(default_door_scale = cloned_door_scale){alert("Does match");}
else{alert("Doesn't match");}



I've tried =, ==, ===, etc, but nothing works.

When I use the following:



alert(default_door_scale);
alert(cloned_door_scale);



the results are identical, yet I cannot get them to qualify.

Maybe they are too complex to compare like this? But I can simply alert these values, so its not like I need to use print_r or anything?


By the way Niko, I found that in order to get coppercube to change a cloned node's properties using behaviours, you actually have to reference the original node name that the current node was cloned from and not use the [the current scene node] option. This is because when the node is cloned, it clones the behaviours too, but changes the node references incrementally. eg; door becomes door1, door2, etc. I had to make sure that I named my cloned nodes accordingly at the point of creation for this to work so that it matches the cloned node references in the behaviours.

Simply using [the current scene node] option does not work for dynamically created clones, but it does work for manually created nodes.


erik
Registered User
Quote
2016-10-13 13:06:44

You should always use names intead of the variable handle you get. If you clone something and want to refer it later to, just set it to a name, or similar. That's what I'm doing.


tim12345
Guest
Quote
2016-10-14 03:32:08

maybe something like this to compare?

if((cloned_door_scale.x+cloned_door_scale.y+cloned_door_scale.z) == (default_door_scale.x+default_door_scale.y+default_door_scale.z))
print("match");
else
print("no match");



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