Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
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 |
||||
|
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? |
||||
|
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. |
||||
|
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) |
||||
|
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 |
||||
|
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:
I've tried =, ==, ===, etc, but nothing works. When I use the following:
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. |
||||
|
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. |
||||
|
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)) |
|