Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
This would be an easy answer fro those who understand functions. I have one where I only want it to run when the input is not null. I have this code below but it still runs when the input is null: I'm guessing this has to do with the first few lines but how to fix ? please respond someone... action_DragDropMod = function() {}; currentlyDraggingAction = null; dontRestartDraggingUntil = 0; action_DragDropMod.prototype.execute = function(currentNode) { var item = ccbGetCopperCubeVariable("pickup"); if (item != null) { var name = ccbGetSceneNodeFromName(item); currentNode = name; } if (dontRestartDraggingUntil != 0) { var now = (new Date()).getTime(); if (dontRestartDraggingUntil > now) return; } if (currentlyDraggingAction) { currentlyDraggingAction.stopDragging(); return; } currentlyDraggingAction = this; var me = this; this.registeredFunction = function() { me.draggingFunc(); }; ccbRegisterOnFrameEvent(this.registeredFunction); this.currentNode = currentNode; var positionNode = ccbGetSceneNodeProperty(currentNode, "Position"); var positionCam = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "Position"); this.distance = positionNode.substract(positionCam).getLength(); var root = ccbGetRootSceneNode(); ccbSetSceneNodeProperty(root,"Gravity",0); ccbSetCopperCubeVariable("jump",0); print("run"); } action_DragDropMod.prototype.stopDragging = function() { this.currentNode = null; var root = ccbGetRootSceneNode(); ccbSetSceneNodeProperty(root,"Gravity",0.5); ccbSetCopperCubeVariable("jump",1); print("end"); ccbUnregisterOnFrameEvent(this.registeredFunction); currentlyDraggingAction = null; dontRestartDraggingUntil = (new Date()).getTime() + 300; } action_DragDropMod.prototype.draggingFunc = function() { var mouseX = ccbGetMousePosX(); var mouseY = ccbGetMousePosY(); var pos3d = ccbGet3DPosFrom2DPos(mouseX, mouseY); var positionCam = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "Position"); var ray = pos3d.substract(positionCam); ray.normalize(); ray.x *= this.distance; ray.y *= this.distance; ray.z *= this.distance; ccbSetSceneNodeProperty(this.currentNode, "Position", ray.x + positionCam.x, ray.y + positionCam.y, ray.z + positionCam.z); } |
||||
|
When I want a function to do something other than null! I put this condition on top and everything else runs if it is really non-null. Well yours just keeps running because there is no "else" if (varname! = null) { code I want executed} else { Â The "else" that you did not specify is simply missing. Â }; . If you do not specify or do when input to null, it will be executed the same way. |
||||
|
I saw this months earlier - just wanted to say thanks for the feedback. |
|