Camera/Trigger Behavior
by rennie moffat · in Torque Game Builder · 12/03/2009 (8:24 am) · 11 replies
@TGB Family, I am posting a behavior I am working on, it does not work yet and if someone could go over the code and if possible (as usual per request) tell me the error of my ways. Glaring errors and bad habits, are what I need help with so, if someone is willing to help me, please, if you can, just point out any glaringly bad habits or obviously clear errors I may have I would appreciate it.
///©renMan3grandHouseProductions
///CameraSetUp, CubeGame
///TorqueScript Engine
///2009
if(!isOject(CameraPositions))
{
%template = new behaviorField(CameraPositions);
%template.friendlyName = "Camera Movement SetUp";
%template.behaviorType = "Camera SetUp";
%template.description = "Camera moves according to this";
///Cameras Stuff
%template.addBehaviorField(CameraYPosition, "Y float of Camera" float, 0);
%template.addBehaviorField(Panel01, "X vector of camera position while on panel 01", float, -75);
%template.addBehaviorField(Panel02, "X vector of camera position while on panel 02", float, 75);
///POSITIONS/SIZING Door aka trigger
%template.addBehaviorField(DoorPosX, "X World Pos of Door", float, 0);
%tempalte.addBehaviorField(DoorPosY, "Y World Pos of Door", float, 0);
%template.addBehaviorField(DoorWidth, "door width" float, 30);
%template.addBehaviorField(DoorHieght, "door hieght", flaot, 10);
///Door force
%template.addBehaviorField(DoorWayForce, "Force of DoorWay Camera Move", float, 30);
///Object which triggers Door to Move Camera.
%template.addBehaviorField(ObjectTrigger, "Object wich triggers trigger(cameraMove)", object, "", t2dSceneObject);
///attach sceneWindow to sceneGraph %this
%template.addBehaviorField(levelA1, "levelA1",object, "",t2dSceneGraph);
}
function CameraPositions::onBehaviorAdd(%this, %scenegraph)
{
sceneWindow2D.mount(%this.owner, "0 0", %this.DoorWayForce);
sceneWindow2D.setCurrentCameraPosition(%this.CameraPanel01, %this.CameraYPosition, 300, 100);
%scenegraph = %this.levelA1;
$cube = %this.ObjectTrigger;
%this.owner.setEnterCallback(true);
%this.cameraMoving = false;
%this.cameraEndMoving = false;
%this.cameraStartMoving = false;
%this.cameraAtStart = true;
%this.enableUpdateCallBack();
}
fucntion CameraPositions::onUpdate()
{
sceneWindow2D.getCurrentCameraPosition(%this.CameraPosition);
}
fucntion CameraPositions::onEnter(%this, %object)
{
%object = %this.ObjectTrigger;
%this.cameraStartMoving = true;
}
function CameraPositions::cameraStartMoving(%this)
{
if(%this.cameraStartMoving == true))
{
sceneWindow2D.startCameraMove(7.0)
}
return;
}
function CameraPositions::cameraEndMoving(%this)
{
if(%this.cameraEndMoving(true))
{
%this.CameraPosition == (%this.Panel02 SPC %this.CameraYPosition);
sceneWindow2D.stopCameraMove();
}
return;
}About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
12/03/2009 (1:00 pm)
@Brian - If any code is placed outside of functions (like the first if statement), the code will immediately execute when the file is exec'd. It's a common way to initialize your game (behaviors, globals, etc.).
#3
And small syntax Im sure may exist but that is small versus learning good technique.
thanks.
@William, I know this will sound bad, but what is my "first statement"?
12/03/2009 (1:56 pm)
@Brian, regarding the "if block containing no function". I am not sure what you mean by that... well let me say I understand what you mean but currently I do not see it. Thanks.And small syntax Im sure may exist but that is small versus learning good technique.
thanks.
@William, I know this will sound bad, but what is my "first statement"?
#4
Guessing is not good technique. Fix the syntax errors, then once you have the behavior doing something, then you can use echo() statements to give you a view into what it's doing.
12/03/2009 (2:18 pm)
Syntax errors are not small. They prevent your script from even being compiled, which means that the engine cannot even attempt to execute your behavior until they're corrected. All you can do right now is guess whether your code might do the right thing if the engine were actually executing it (which it isn't).Guessing is not good technique. Fix the syntax errors, then once you have the behavior doing something, then you can use echo() statements to give you a view into what it's doing.
#5
Hmm, that sounds like a plan.
SEE! Still technique.
12/03/2009 (2:33 pm)
True, perhaps that was arrogant of me to say.Hmm, that sounds like a plan.
SEE! Still technique.
#6
I remember now@!
Sorry I was working late, and I did run a syntax, but it exists at line 16, and I remember I could not figure t out.
Perhaps that was arrogant of me to post, thinking that wasn't a major issue.
If some one can help spot the error in Line 16. It is a parse error. the ##^## occurs jut before %template again, on line 16.
thanks,
Ren
12/03/2009 (2:37 pm)
PS.I remember now@!
Sorry I was working late, and I did run a syntax, but it exists at line 16, and I remember I could not figure t out.
Perhaps that was arrogant of me to post, thinking that wasn't a major issue.
If some one can help spot the error in Line 16. It is a parse error. the ##^## occurs jut before %template again, on line 16.
thanks,
Ren
#7
I promise syntax errors will NOT be brought to the board again. I am sorry for that sincerely @ =all.
I would still like to request a bit of help figuring out the bigger picture.
questions pending.
Thanks again,
so sorry, me love me long time,
ren
12/03/2009 (2:39 pm)
I am sorry again...I promise syntax errors will NOT be brought to the board again. I am sorry for that sincerely @ =all.
I would still like to request a bit of help figuring out the bigger picture.
questions pending.
Thanks again,
so sorry, me love me long time,
ren
#8
%template = new behaviorFIELD
not template.
But alas, she STILL CRASHES so the hunt is on. again, not to bother but helping me understand any problems is of most importance. To me anyways,
cheers
12/03/2009 (2:42 pm)
s. the error was, I had line 16 eroor, I spotted line X sais%template = new behaviorFIELD
not template.
But alas, she STILL CRASHES so the hunt is on. again, not to bother but helping me understand any problems is of most importance. To me anyways,
cheers
#9
I think thats why i did not emphasize crashes at first with syntax as MAJOR importance to me, what will take me 5 hours over 5 seconds is how to program (ps i hope its not that long) is if any exists... Major programming errors. will continue on.
thank you.
Ren
12/03/2009 (2:44 pm)
PS.I think thats why i did not emphasize crashes at first with syntax as MAJOR importance to me, what will take me 5 hours over 5 seconds is how to program (ps i hope its not that long) is if any exists... Major programming errors. will continue on.
thank you.
Ren
#10
I'm glad I asked!
12/03/2009 (2:56 pm)
Quote:@Brian - If any code is placed outside of functions (like the first if statement), the code will immediately execute when the file is exec'd. It's a common way to initialize your game (behaviors, globals, etc.).
I'm glad I asked!
#11
!!!!
12/03/2009 (4:24 pm)
About to consolidate my movements into 3 separate behaviors, one for the trigger, the object AND the camera. !!!!
Torque Owner Brian Pickrell
There's also a typo on Line 57.