Creating Behaviours
by rennie moffat · in Torque Game Builder · 06/14/2009 (12:48 pm) · 4 replies
Hi there, relative newbie.
I began to program my first solo project, a simple 2D scroll shooter and I have run into a problem. No Behaviour will show. I know this seems really beginner to ask this but...
1.I have insured the file is called in game/ main.cs
__________________
function initializeProject()
{
// Load up the in game gui.
exec("~/gui/mainScreen.gui");
// Exec game scripts.
exec("./gameScripts/game.cs");
// Exec game scripts.
exec("./gameScripts/player.cs");
I have insured the name "player" corresponds to the name of the behaviour/player.cs
_______________
function playerMovement::onLevelLoaded(%this, %scenegraph)
{
// Store a reference to the player's ship in a global variable
$player = %this;
moveMap.bindCmd(keyboard, "up", "jump();");
moveMap.bindCmd(keyboard, "down", "crouch();", "crouchStop();");
moveMap.bindCmd(keyboard, "left", "walkLeft();", "walkLeftStop();");
moveMap.bindCmd(keyboard, "right", "walkRight();", "walkRightStop();");
}
I have then declared these instructions, movement types in the following code, in the same player.cs file
_______________
function walkRight()
{
$player.moveRight = true;
$player.updateMovement();
}
function walkLeftStop()
{
$player.moveLeft = false;
$player.updateMovement();
}
function walkRightStop()
{
$player.walkRight = false;
$player.updateMovement();
}
etc. (repeated for various movemnts but formula is the same. I have done all of this but when I select my playerImage, define its class, "player" then look for it in the behaviours list, notta.
Can somebody help me please!
I began to program my first solo project, a simple 2D scroll shooter and I have run into a problem. No Behaviour will show. I know this seems really beginner to ask this but...
1.I have insured the file is called in game/ main.cs
__________________
function initializeProject()
{
// Load up the in game gui.
exec("~/gui/mainScreen.gui");
// Exec game scripts.
exec("./gameScripts/game.cs");
// Exec game scripts.
exec("./gameScripts/player.cs");
I have insured the name "player" corresponds to the name of the behaviour/player.cs
_______________
function playerMovement::onLevelLoaded(%this, %scenegraph)
{
// Store a reference to the player's ship in a global variable
$player = %this;
moveMap.bindCmd(keyboard, "up", "jump();");
moveMap.bindCmd(keyboard, "down", "crouch();", "crouchStop();");
moveMap.bindCmd(keyboard, "left", "walkLeft();", "walkLeftStop();");
moveMap.bindCmd(keyboard, "right", "walkRight();", "walkRightStop();");
}
I have then declared these instructions, movement types in the following code, in the same player.cs file
_______________
function walkRight()
{
$player.moveRight = true;
$player.updateMovement();
}
function walkLeftStop()
{
$player.moveLeft = false;
$player.updateMovement();
}
function walkRightStop()
{
$player.walkRight = false;
$player.updateMovement();
}
etc. (repeated for various movemnts but formula is the same. I have done all of this but when I select my playerImage, define its class, "player" then look for it in the behaviours list, notta.
Can somebody help me please!
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
My advice; go straight to typing gamescripts. Objects recognize gamescripts via named object in a scene, and gamescripts ignore the '.owner' check when looking at objects. All you need to do is add it to the list of things to execute in the main.cs document.
This tutorial here uses gamescripts:
http://tdn.garagegames.com/wiki/TGB/Tutorials/Platformer
Though direct gamescripts aren't as dynamic, they're easier to manage (at least for me).
06/17/2009 (3:26 pm)
I never liked behaviors... I always seem to run into problems, particularly when building the project to run on other Operating Systems.My advice; go straight to typing gamescripts. Objects recognize gamescripts via named object in a scene, and gamescripts ignore the '.owner' check when looking at objects. All you need to do is add it to the list of things to execute in the main.cs document.
This tutorial here uses gamescripts:
http://tdn.garagegames.com/wiki/TGB/Tutorials/Platformer
Though direct gamescripts aren't as dynamic, they're easier to manage (at least for me).
#3
06/17/2009 (4:35 pm)
yah i seemed to notice that post posting this thread. All tutorials I have done have had fully interactive players that had no behaviors declared in the console.
#4
addBehaviourField.
is the following script going to add a behaviour to the console which must be declared/linked to the relevant object? I would think so, but just asking. IF so, what is the benifit of declaring your objects movemnts like this vs a moveMap.Bind(keyboard... for example?
Thanks
Ren
if (!isObject(UFOMovement))
{
%template = new BehaviorTemplate(UFOMovement);
%template.friendlyName = "UFO Controls";
%template.behaviorType = "Input";
%template.description = "UFO movement control";
%template.addBehaviorField(upKey, "Key to bind to ascend", keybind, "keyboard up");
%template.addBehaviorField(downKey, "Key to bind to decend", keybind, "keyboard down");
%template.addBehaviorField(leftKey, "Key to bind to move left", keybind, "keyboard left");
%template.addBehaviorField(rightKey, "Key to bind to move right", keybind, "keyboard right");
%template.addBehaviorField(VerticalSpeed, "Vertical acceleration", float, 7.5);
%template.addBehaviorField(HorizontalSpeed, "Horizontal acceleration", float, 15.0);
%template.addBehaviorField(damping, "Damp movement", float, 5.0);
}
06/17/2009 (5:48 pm)
Just noticed something in a new tutorial. addBehaviourField.
is the following script going to add a behaviour to the console which must be declared/linked to the relevant object? I would think so, but just asking. IF so, what is the benifit of declaring your objects movemnts like this vs a moveMap.Bind(keyboard... for example?
Thanks
Ren
if (!isObject(UFOMovement))
{
%template = new BehaviorTemplate(UFOMovement);
%template.friendlyName = "UFO Controls";
%template.behaviorType = "Input";
%template.description = "UFO movement control";
%template.addBehaviorField(upKey, "Key to bind to ascend", keybind, "keyboard up");
%template.addBehaviorField(downKey, "Key to bind to decend", keybind, "keyboard down");
%template.addBehaviorField(leftKey, "Key to bind to move left", keybind, "keyboard left");
%template.addBehaviorField(rightKey, "Key to bind to move right", keybind, "keyboard right");
%template.addBehaviorField(VerticalSpeed, "Vertical acceleration", float, 7.5);
%template.addBehaviorField(HorizontalSpeed, "Horizontal acceleration", float, 15.0);
%template.addBehaviorField(damping, "Damp movement", float, 5.0);
}
Torque Owner rennie moffat
Renman3000
I really hope someone can help me on this as I am sure it is something so tiny, so miniscule.
So I simply copy and pasted a movement behavior, that works from a tutorial. I selected my sprite, the behaviors drop down now shows my new behavior. I selected it. I ran the game but my sprite does not move at all. It does not respond to any key inputs. IS there something obvious I am missing here?
Thanks
Ren