frostline-et Registered User |
Quote
|
2020-11-17 16:26:25 |
|
Can anyone point out the syntax errors in this code?
/* <behavior jsname="behavior_cubeMovement" description="Cube Movement"> </behavior> */ behavior_cubeMovement = function() { var cpos = ccbGetSceneNodeProperty("Cube1", "Position"); var npos = new vector3d(0.2, 0.0, 0.0); var go; };
behavior_cubeMovement.prototype.onAnimate = function("Cube1"); { ccbRegisterKeyDownEvent("keyDown"); function keyDown(87) { go = cpos.add(npos); ccbSetSceneNodeProperty("Cube1", "Position", go); } }
|
Robo Guest |
Quote
|
2020-11-18 00:09:23 |
|
Post your code into this will help a lot:
https://esprima.org/demo/validate.html
seems functions don't need quotation marks inside the brackets...
|
veganpete Registered User |
Quote
|
2020-11-18 12:23:39 |
|
I don't know the first thing about coding but to me it looks as though "var go" hasn't been defined at the start.
The end section of code then tries to use "go" with the "cPOS" and "nPOS" variables.
Maybe try defining "var go" in the first section of code as well as cPOS and nPOS?
Sorry, just a guess. :'(
|
carlosm Registered User |
Quote
|
2020-11-28 01:35:29 |
|
Try this one!
/ * <behavior jsname = "behavior_cubeMovement" description = "Cube movement"> <property name = "Cube" type = "scenenode" />
</behavior> * / behavior_cubeMovement = function (){ this.cpos = ccbGetSceneNodeProperty (this.Cube, "Position"); this.npos = new 3d vector (0.2, 0.0, 0.0); this.go; this.Forward = false;
};
behavior_cubeMovement.prototype.onAnimate = function(node, timeMs){ if(this.Forward == true){ this.go = this.cpos.add(this.npos); ccbSetSceneNodeProperty (this.Cube, "Position", this.go); }
}
behavior_cubeMovement.prototype.onKeyEvent = function(keyCode, pressed){
var key_s = 87;
if (keyCode == key_s){ if (pressed == true) this.Forward = true; if (pressed == false) this.Forward = false; }
}
|