Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Stop a function

Robo
Guest
Quote
2019-09-12 05:44:14

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);
}


carlosm
Registered User
Quote
2019-11-26 04:15:39

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.


Robo
Guest
Quote
2020-03-03 03:51:32

I saw this months earlier - just wanted to say thanks for the feedback.


Create reply:


Posted by: (you are not logged in)


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