Game Development Community

This might be a stupid question but......

by Matthew Fisher · in General Discussion · 03/14/2006 (4:57 pm) · 6 replies

Thanks for checking out this thread

i purchased the 3dgpai1 book, and subsequently purchased a torque license, jumped in with both feet right away. before torque, the only engine i've worked with is neverwiinter's aurora engine, the scripting is simple and is VERY close in form and function to c++. now, maybe i've missed something in reading ken finney's book but i'm absolutely lost with torque script. 3dgpai1 shows you how to set up a simple game but it vaguely explains what is actually going on in the script or where to reference functions and the like to figure it out on my own.

this is a line from one of the scripts, for example:

$pref::Video::displayDevice = "OpenGL";

the "::", double colon thing is blowing my mind, it doesn't explain anywhere what relationship this has to c++ syntax, or where can i find a list of functions such has "displayDevice". nowhere does he cover source code or it's relationship to the torque scripting language.

so, my question is, should i discard the book examples and start fresh with the torque SDK docs and tutorials, or will i end up being just a lost?

i've been working with milkshape and uv mapping to make models and i think i found something i'm really interested in. i even purchased a milkshape license and purchased a better uv mapper prog (ultimate unwrap3d), and i might add, is alot better than uv mapper that comes with the book. it's fun, i really enjoy this stuff. it just seems i can't do much with it because the book is so limited in it's explanation of what is going on in the code to produce the result.

thanks again for your time.

#1
03/14/2006 (5:31 pm)
Hey Matthew,

It's tough to get used to, I know. But don't worry, with time all will become absorbed.

As to your specific example, I would check page 127, where he gives an explanation of Namespaces. Namespaces are one of the things that people new to this have a tough time wrapping their brains around (as I did; datablocks are another one -- which, not coincidentally, are covered briefly on page 128).

The $pref::Video::displayDevice portion actually is a variable, not a function (hence the preceding $; functions would have parentheses +/- arguments at the end). The double colons define arbitrary contexts for the variable. As Ken says, namespaces are means of defining a formal context for variables. So with your example, the displayDevice variable falls under the pref::Video namespace, which itself is a subcomponent of the pref namespace.

The identifier between the "$" and the "::" is completely arbitrary, but it sets the context for a particular variable. So if you had two variables named

$pref::maxplayers
$game::maxplayers

then, even though they both are called "maxplayers", they refer to different variables because of the different contexts (ie, namespaces).

As to your other question, that's a tough one. Once I got to Chapter 4 in the book, things became a lot more confusing for me. At that point, I put it down and just went through online tutorials and fought my way through the scripts. After a while of doing that, I found I understood so much more than just reading the book. Now, the book makes much more sense to me.
#2
03/16/2006 (6:15 am)
Thanks rubes

so namespaces are like declarations? is it so torque can manage and organize the variables in memory more efficiently? i just don't see what the benefit/difference between-

$prefVideodisplayDevice and $pref::video::displayDevice are other than the later being easier to read.

or is it so variables can more easily be passed into multiple "namespaces" just by adding one particular variable's tag to that namespace?

am i even close on this?

next question would be, since torque recognizes the variable $pref::Video::displayDevice , and more specifically the displaydevice part, where can i get a master list of all the variables that torque recognizes?

i'm not even ready for datablocks yet.

thanks again rubes.:)
#3
03/16/2006 (8:40 am)
Quote:
i just don't see what the benefit/difference between-

$prefVideodisplayDevice and $pref::video::displayDevice are other than the later being easier to read.

or is it so variables can more easily be passed into multiple "namespaces" just by adding one particular variable's tag to that namespace?

To be perfectly honest, I'm not completely certain, although I'm reasonably sure it is the latter.

Quote:
next question would be, since torque recognizes the variable $pref::Video::displayDevice , and more specifically the displaydevice part, where can i get a master list of all the variables that torque recognizes?

I would start by checking here and here. Then I would consider checking out this resource.
#4
03/16/2006 (11:50 am)
It is not a declaration.

maybe could be explained like this:
it indicates in which space (namespace) that variable exists. this is why these two lines
$pref::maxplayers
$game::maxplayers
talk about two diffeent 'maxplayers'

maxplayer in the namespace pref is different from the maxplayers in the namespace game.

Still, that is only an example to exaplin the concept of namespaces, to be honest I wouldn't use identical names for different variables even between local and variable ones just to avoid tired eyes confusion later on
#5
03/16/2006 (4:05 pm)
Thanks for the help guys. rubes, those links have been very helpful.

Quote:to be honest I wouldn't use identical names for different variables even between local and variable ones just to avoid tired eyes confusion later on

i totally agree.

then you have to wonder, what is the actual intent for namespaces, what benefit were the engine programmers shooting for. i mean, if it isn't anything more than a way to clearify variables, why make a it necessary in a "typeless" scripting language? it's like putting a Briggs and Stratton in a ferrari.

it must be a technical thing, something important like memory management and addressing.

i'm not lost on the issue so much anymore, just a bit confused.

thanks again
#6
03/16/2006 (5:00 pm)
If you want to see all of the variables that you are currently using in their alphabetical order, you can use this little helper function I wrote for just that purpose...


function vars()
{
	export("$*", "./vars.cs");
}



The above code will create a file called "vars.cs" in whatever directory you are are currently under, so you might have to check around for it, but inside that file you'll find all the current variables in memory.


EDIT: Just drop that at the bottom of one of your files that gets exec'ed(main.cs is fine) and then once you load up the game(or whatever) open your console and type in "vars();" without the quotes and hit enter, then you can find the file and open it.