Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hi guys, I'm hoping someone can tell me why this registered function fails to pickup the speed as shown below. Everything works as expected to open 2x doors except when I ask it to get the variable 'this.speed' from the above function using 'me' instead of 'this' which is the right way to do it I have read. If I replace "me.speed" with a number like 0.06 or whatever then it works correctly.... ????? // function var DoorOpen = function work() { var me = this; this.registeredFunction = function() { me.openClose(); }; ccbRegisterOnFrameEvent(this.registeredFunction); this.action = doorAction; this.axis = doorAxis; this.nuDoors = invDoors[idx+5]; this.moveAmount = invDoors[idx+6]; this.OC = 0; if (this.nuDoors == 1) { this.drS = drS; this.drSstart = drSPos; this.speed = drSspeed; } else { this.drU = dr1; this.drUstart = dr1Pos; this.drD = dr2; this.drDstart = dr2Pos; // this.speed = invDoors[idx+8]; // this is where it goes wrong and wont pickup speed below this.speed = 0.06; }} function openClose() { var me = this; if (me.action == "O") me.OC = me.OC + me.speed; if (me.action == "C") me.OC = me.OC - me.speed; if (me.axis == "X") { ccbSetSceneNodeProperty(me.drU, "Position", me.drUstart.x + me.OC, me.drUstart.y, me.drUstart.z); ccbSetSceneNodeProperty(me.drD, "Position", me.drDstart.x - me.OC, me.drDstart.y, me.drDstart.z); } else if (me.axis == "Y") { ccbSetSceneNodeProperty(me.drU, "Position", me.drUstart.x, me.drUstart.y + me.OC, me.drUstart.z); ccbSetSceneNodeProperty(me.drD, "Position", me.drDstart.x, me.drDstart.y - me.OC, me.drDstart.z); } else if (me.axis == "Z") { ccbSetSceneNodeProperty(me.drU, "Position", me.drUstart.x, me.drUstart.y, me.drUstart.z + me.OC); ccbSetSceneNodeProperty(me.drD, "Position", me.drDstart.x, me.drDstart.y, me.drDstart.z - me.OC); } if (me.OC >= me.moveAmount || me.OC <= -(me.moveAmount)) { ccbUnregisterOnFrameEvent(this.registeredFunction); }} DoorOpen(); |
||||
|
With a bit of fuss, I found a solution that worked. Firstly 'speed' was being referenced to a different block of javascript code even though not mentioned in this one...strange so I changed the variable. Then I had to re-arrange the code to get it to work - the last part like this: function openClose() { var me = this; if (me.action == "O") { me.OC = me.OC + me.Spd; } else if (me.action == "C") { me.OC = me.OC - me.Spd; } if (me.OC > me.moveLen || me.OC < -(me.moveLen)) { ccbUnregisterOnFrameEvent(this.registeredFunction); } if (me.axis == "X") { ccbSetSceneNodeProperty(me.drU, "Position", me.drUstart.x + me.OC, me.drUstart.y, me.drUstart.z); ccbSetSceneNodeProperty(me.drD, "Position", me.drDstart.x - me.OC, me.drDstart.y, me.drDstart.z); } else if (me.axis == "Y") { ccbSetSceneNodeProperty(me.drU, "Position", me.drUstart.x, me.drUstart.y + me.OC, me.drUstart.z); ccbSetSceneNodeProperty(me.drD, "Position", me.drDstart.x, me.drDstart.y - me.OC, me.drDstart.z); } else if (me.axis == "Z") { ccbSetSceneNodeProperty(me.drU, "Position", me.drUstart.x, me.drUstart.y, me.drUstart.z + me.OC); ccbSetSceneNodeProperty(me.drD, "Position", me.drDstart.x, me.drDstart.y, me.drDstart.z - me.OC); } } |
|