Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Action script crash problem

hadoken
Guest
Quote
2021-03-29 20:38:42

Does anyone have a glue why the following action script crashes in CC when used with "When a key is pressed do something" ?


/*
<action jsname="action_AiMoveTo" description="Move AI npc to target node's position">
<property name="npc" type="scenenode" />
<property name="Target" type="scenenode" />
</action>
*/

action_AiMoveTo = function()
{

}


action_AiMoveTo.prototype.execute = function()
{
var npc = ccbGetSceneNodeFromName(this.npc);
var target = ccbGetSceneNodeFromName(this.Target);
var targetpos = ccbGetSceneNodeProperty(target, "Position");

ccbAICommand(npc, "moveto", targetpos);
}



If I use the following "Execute Javascript" instead of having executed the action script it works but with error "Could not get property, provided scene node is invalid":


var npc = ccbGetSceneNodeFromName("npc");
var target = ccbGetSceneNodeFromName("Target");
var targetpos = ccbGetSceneNodeProperty(target, "Position");
ccbAICommand(npc, "moveto", targetpos);


Maybe I missed something with the AI requirements? Thanks for any help.


Robo
Guest
Quote
2021-03-30 10:40:58

If I had to take a guess would be the possible conflict between "this.npc" and "npc" variables in the first.

I would not use the same name, see if when you change makes any difference.


hadoken
Guest
Quote
2021-03-30 11:17:35

Thanks @Robo for the idea.

After following your advice, it unfortunately still crashes.


just_in_case
Moderator
Quote
2021-03-30 13:16:26

there are a few mistakes in your script code as I can see.
you are using
 ccbGetSceneNodeFromName
in a wrong method. while you don't have to use this code at all.
if you ever wish to use that code, then you can't use it with properties of the action like you are using
 this.npc and this.Target
you need to use the name of actual object from the editor in string format like this
"cubeMesh1


so instead of using
 ccbGetSceneNodeFromName(this.npc);
use
ccbGetSceneNodeFromName("npc");


however if you are using property as a type of "scenenode" then you actually don't have to use the above command to get the name of the scenenode.

you can directly call an object or change its properties by using
this.propertyname
property should be a type of scenenode.
then you can simply use this command to get the position of an object
 var targetpos = ccbGetSceneNodeFromName(this.Target,"Position");


there is no need to call the object by name simply use the property type.

so this makes the whole code corrupted and you get an error could not get the property because you are calling the object in the wrong fashion.

here is how the final script should goes:-

/*
<action jsname="action_AiMoveTo" description="Move AI npc to target node's position">
<property name="npc" type="scenenode" />
<property name="Target" type="scenenode" />
</action>
*/

action_AiMoveTo = function()
{

};


action_AiMoveTo.prototype.execute = function(currentNode)
{

var targetpos = ccbGetSceneNodeProperty(this.Target, "Position");

ccbAICommand(this.npc, "moveto", targetpos);
};


hopefully, this should work. let me know if this don't works.






hadoken
Guest
Quote
2021-03-30 14:21:04

Thanks for the helpful lesson @just_in_case!
Now the scripts works totally fine.

Among other experts you're a blessing here, coffee-supported you back ;-)


just_in_case
Moderator
Quote
2021-03-30 18:54:27

Thanks a lot @ Hadoken 😇 thats really gonna help😇


Create reply:


Posted by: (you are not logged in)


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