Game Development Community

$pref-- Whah?

by Jeff Osborn · in Torque Game Engine · 05/24/2004 (9:30 pm) · 5 replies

So, can anyone tell me about how $pref works?

What is $pref? My guess is that it is used to set default values for instances of the class it references (like $pref::Audio::masterVolume sets the master volume). If this is the case, I can't figure out for the life of me how it hooks into the Audio namespace.

What I started out doing was working from the top-- I opened up main.cs under the starter.fps demo, and started walking through the code. I figured that if I just tried to work through the code by example I could figure it out and right away I ran into $pref. Is there any DOC on $pref and how it affects the engine?

Thanks.

#1
05/24/2004 (9:43 pm)
It doesn't do anything special.

$Pref:: is just a prefix applied to all variables that you want Torque to automagically save to disk in the prefs.cs files. The :: operator doesn't exist in TorqueScript so there is no real Pref namespace nor does it tie into the C++ namespaces in any way.

It's just a matter of organization that all the audio stuff lives in $Pref::Audio::.

Hope that clears things up a bit. :)
#2
05/24/2004 (9:51 pm)
Thank you.

I had pretty much stumbled onto that realization a coupla minutes ago. I just couldn't find the references in C++ so I figured it as script-side only.

In fact, the "Hall of Worlds" documentation says something about :: not being anything special.

Sometimes the background in C++ DOESN'T help with torque script... I keep expecting :: scoping operator to mean something when used in a variable name...

AND IT DOESN'T!

That's not true for functions, though is it?
#3
05/24/2004 (9:58 pm)
Actually, it means nothing for functions. :)

Name lookups ARE done as if it meant something, but it doesn't.

If that makes sense. :)
#4
05/24/2004 (10:13 pm)
Er-- wait.

So how do you override base class functions? In the Hall of Worlds docs, the talk about accessing the Player namespace with the Player:: prefix. According to them, if a scoping prefix (in this case, "Player") is recognized as a namespace in the engine, then it's a scope.

If the stuff ahead of "::" is not a recognized namespace (for instance, $Poofters::Froth::Wyoming), then it's just a variable, in this case global because of the '$'.

So, is that true or am I about to become severely confused?

Thanks.
#5
05/25/2004 (7:50 am)
You can make arbitrary function names, like Pony::spawnHerd(), that don't correspond to anything.

But if you are working with an object of a given class, say an AiPlayer object, and you call a method, say setEnergy, it will look for AiPlayer::setEnergy, then Player::setEnergy, then ShapeBase::setEnergy... These names are generated by taking the method name and prefixing the various classes in the hierarchy to it.

So there's no validation of script function names against namespaces but they are searched as if they were in namespaces when you make method calls.

It's sort of a poor man's OOP. :)

So everything acts (pretty much) like it should in C++, but it isn't validated or dependent on definitions like C++ is.