Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
CurrentNode's name from action

hadoken
Guest
Quote
2021-04-07 14:21:43

I'm having difficulties getting the current node's name from within an action. How can this be fixed? Thanks for any help.

/*
<action jsname="action_PrintCurrentNodeName" description="print name of current scene node">
</action>
*/

action_PrintCurrentNodeName = function()
{

};

action_PrintCurrentNodeName.prototype.execute = function(currentNode)
{

var node = ccbGetCurrentNode();
var name = ccbGetSceneNodeProperty(node, "Name");
print("current name= "+ name);


};



just_in_case
Moderator
Quote
2021-04-07 15:58:29

@hadoken
ccbGetCurrentNode()
only works in execute javascript action.

To get the current node in the action you can simply use "currentNode"

so your action will look like this. If you want you can use 'currentNode' directly to get the property, you don't have to define it as a variable.

/*
<action jsname="action_PrintCurrentNodeName" description="print name of current scene node">
</action>
*/

action_PrintCurrentNodeName = function()
{

};

action_PrintCurrentNodeName.prototype.execute = function(currentNode)
{

var node = currentNode;
var name = ccbGetSceneNodeProperty(node, "Name");
//var name = ccbGetSceneNodeProperty(currentNode, "Name"); // remove the above 2 lines and uncomment this line's code.
print("current name= "+ name);


};


you can use this to print the name of the current scene node.






hadoken
Guest
Quote
2021-04-07 16:53:54

@just_in_case

Thank you very much for the fixed action script which delivers the correct current scene node name triggered by a built-in "When a key is pressed do something" behavior.

Is there any possibility to also retrieve the current node triggered by the built-in "Every few seconds do something" behavior which is giving me an
"Could not get property, provided scene node is invalid."
error so far resulting in "current name=false" ?


just_in_case
Moderator
Quote
2021-04-07 16:58:49

the above script should work fine with every behavior. I tried it myself with the every few seconds behavior and set time MS as "1" lowest possible and it worked for me.

crosscheck if you had made any changes to the above script.


hadoken
Guest
Quote
2021-04-07 17:15:30

You are right - in fact it's working very well now, I just accidentally deleted the most important line in the header:
<property name="Node" type="scenenode" default="" />

Sorry for the false alarm & many thanks @just_in_case, you're the best!

Besides, if your times allows could you maybe also have another look at my javascript-"wait" issue from my last post at:
https://ambiera.com/forum.php?t=... ?

THX


just_in_case
Moderator
Quote
2021-04-08 06:01:22

yes you can use the below code to set the timer.

this.startTime = (new Date()).getTime();			//start the timer 
this.endTime = this.startTime + 1400; //1400 is the time duration (timer to end in)


insert the above code into your script where you want to trigger the timer to get started. Generally in the key pressed events.

then you need to add this bit of code into your "onAnimate" section in your behavior or by registering an onframevent using the command ccbRegisterOnFrameEvent().


var now = (new Date()).getTime();//this the timer which compares the time stored in keyEvents function and then check it with the current time
if (now > this.endTime)
{ //your code which you want to execute after the timer ends goes in here.
};


this will set the timer according to the time provided when the code is executed on keypresses. and then it compares it with the time going on each frame and then if the time on each frame is greater than the time stored when the key was pressed then it will execute the code provided.

hope you understand it.


Create reply:


Posted by: (you are not logged in)


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