Game Development Community

Which script commands(documentation)work in sections of editor?

by B. Spencer · in Torque Game Builder · 05/16/2008 (5:03 am) · 5 replies

Hi All,

When creating a script file for an object, could I just put in say for instance the camera shake function, or do I have to create a separate script file that would connect to the camera in the editor, and then have it interact with my object script?

I looking to find out how to setup what script commands work with the different functions of the editor. Like some sort of template to start with. Or is it possible to create scripts in any order I want them, or do they have to be structured (say for instance what scripts in reference work with the scene editor, camera, etc)?

Also when creating GUI elements, what is the best way to create them(behaviors, or GUI Editor)?



Thanks in Advance!

B. Spencer

#1
05/16/2008 (12:45 pm)
Woh, unfortunately I didn't understand anything in your post. Maybe you can post something very specific you want to do, and by explaining that it will hopefully give you a sense of how things "work" in general in TGB?
#2
05/16/2008 (2:00 pm)
I've just updated my topic for this post, hopefully this may help you understand what I'm asking.
#3
05/16/2008 (2:06 pm)
I think I understand the confusion a bit more with the follow-up, so here are some primer thoughts:

--TorqueScript files are only a method of organization--you could literally put your entire game into one .cs file and it would run fine. It's a good practice to sort your functions based on the class(es) they are going to work on, but that's simply to make things easier for you as a developer.

--the only "ties" between the Level Builder (including the objects you place in your world within the level builder) and your game are based on a concept called "namespaces". Basically, TorqueScript will react to things that happen within the engine based on the namespace that the object has defined, which is controlled by 3 fields and one property in the level builder:

--Object Type--StaticSprite, AnimatedSprite, TileMap, SceneObject--each of these define what type of object any level builder (or TorqueScript) created object is, and this is added to that object's namespace.
--Object Name--the editor field "name" in the Scripting Tab for each object adds that name to a namespace.
--Object Class--another editor field in the same place that adds a second tie to the object's namespace.
--object SuperClass--a third tie of the same type as the previous two.

Now, once your game is running, what happens is that the engine is going to do quite a bit of work underneath the scenes, and your TorqueScript responds to events that occur within the engine based on a concept called "Callbacks". For example, here's a basic callback:

function [b]t2dStaticSprite[/b]::[i]onLevelLoaded[/i](%this, %sceneGraph)
{
  // put code here to do something when any StaticSprite in your level is loaded into the game
}

The bold portion: t2dStaticSprite is the namespace to use for this function, and the italic part: onLevelLoaded is the event that the engine triggers. When the event triggers, it looks for a namespace method such as the one above that contains code to execute, and if it finds a method, then it goes ahead and runs that code.

You will see quite a bit of this use within the Fish and WhackaMole tutorials (as well as the rest), and it's a fundamental concept to understand for successful TGB development, so please ask any questions at all that will help make it clear!
#4
07/10/2008 (1:51 am)
I've been looking in the documentation(script reference).
Wanted to know if its possible to use methods from other functions to accomplish certain tasks, and make creative solutions?
#5
07/10/2008 (10:10 am)
What specifically are you trying to do?

Maybe this will help, but I'm not really sure...

A scriptFunction can be used anywhere at anytime. A scriptMethod must be called on an object of the correct class. Also, scriptFunction/scriptMethod means the same thing as consoleFunction/consoleMethod.

%word = getWord("one two three", 1);  // getWord( string, U32 idx ) is a scriptFunction
echo( %word );   // echo( string ) is a scriptFunction

%set = new SimSet();
%obj = new SimObject();
%set.add( %obj );   // SimSet::add( simObject ) is a scriptMethod

%set.echo( "bla" ); // this will generate a console error like ..
                               // ScriptMethod "echo" does not exist for object (id#)