Game Development Community

Basics

by Howard Dortch · in Torque Game Engine · 07/07/2004 (8:52 am) · 10 replies

Would this be a place to ask questions about scripting basics? The book has a lot of good information but there are some parts of scripting that still elude me.

#1
07/07/2004 (9:26 am)
I would move it to the MODS section of the Forums, this area is strictly devoted to Ken's book and chapters where readers need guidance, I think.
#2
07/07/2004 (9:54 am)
Well I was using chapter 4 of the book as a reference to questions I might have. The Mods forum looks like people already know things way beyond my understanding.
#3
07/07/2004 (6:14 pm)
What's your actual question ?
#4
07/08/2004 (3:47 am)
In control/server.cs

%player = new Player() {
dataBlock = MaleAvatar;
client = %this;
};

1. %player is a handle new Player object created ? If so is there is list of objects that can be created?
2. by setting dataBlock = MaleAvatar does the Avatar class automaticly get instanciated and function Avatar::onAdd(%this,%obj) automaticly get called?

3. Most everything I see in the scripts have a $ or % reference. dataBlock and client dont have any references so are they actually
%player.dataBlock and %player.client ?
#5
07/08/2004 (4:21 am)
Since we are creating a new player object, the initializations take place in the scope of the new statement (notice they are in the curly brackets {} for the new statement.) This means that they are inherently using the %player object. So it is almost the same as doing the following:

%player.dataBlock = MaleAvatar;
%player.client = %this;
#6
07/08/2004 (6:17 pm)
Q1 :
Yes, there is a list of classes that can be used to instantiate new objects. Or you can create a new class that inherits from the ones availbles. ie. Item, shapeBase, Player, Vehicle, FlyingVehicle....

Q2 :
One thing that is very confusing but you MUST get used to it is the difference between Datablocks and Classes. I don't remind if Avatar is a Class or a Datablock but check other resources about that for sure.

Q3:

Matthew answered that one.

HTH
#7
07/08/2004 (6:53 pm)
@Bruno where is the list? I would like to know what all I can create.

Avatar is a class defined in a datablock, so if the data block gets used to create an object does the class Avatar get instanciated automaticly as a result?
#8
07/08/2004 (8:09 pm)
Slightly more authoritative answers:

1. %player stores the object ID of the new player object. Any class exposed to the scripting engine can be created. There isn't an official list - try grepping the source code (C++) for DECLARE_CONOBJECT. You can also use the script autodocumentor to generate a list.

2. No. MaleAvatar is the name of an object. You can reference objects in four ways:

// By ID number.
1234.dump();

// By name.
MaleAvatar.dump();

// By a variable, either global...
$foo.dump();

// Or local...
%foo.dump();

You can give an object a name by specifying it when you create it, ie:

%player = new Player(MyPlayer) { .. };

Names are global. The most recently created object of a given name is the one that will be found when you use that name.

3. As Matthew explains, the fact that the variables are in curly braces gives them a special meaning:

%foo = new Player()
{
   datablock = MaleAvater;
   client = %this;
};

// Above is almost the same as...
%foo = new Player();
%foo.dataBlock = MaleAvater;
%foo.client = %this;

EXCEPT, as he points out, in the former case the variables are assigned "before" the object is created, while in the latter case they are assigned "after."

And to your most recent question, the answer is no. The MaleAvater datablock already exists; all that is stored is a reference.
#9
07/09/2004 (3:16 am)
"Names are global. The most recently created object of a given name is the one that will be found when you use that name."

Smells like a hash table to me. :)
#10
01/27/2006 (1:24 pm)
When I tried to set the name via script, it was treated as a dynamic field and not the name. Could ya mind posting the code to set the name in the new player example above? thanks