Game Development Community

which is a Namespace??

by Yue -Rookie Torque 3D- · in Torque 3D Beginner · 09/02/2013 (3:10 pm) · 7 replies

Hello, ignorance has me broke, just that: it is a namespace and an example of its use.

Thanks and regards.

About the author

http://www.iris3d.tk -Games Studios- <<I do not speak English: I use the google translator>> My goal as a rookie is knowing Torque 3D


#1
09/03/2013 (11:18 am)
Anyone is welcome to correct me on this but I believe a namespace is e.g:
function namespace::onCollision()
For example:
new ScriptObject(testObject);
//testObject is now the namespace for that object
function testObject::testFunction() { echo("foo"); }
testObject.testFunction(); // echoes "foo"
Thats specifically for TorqueScript tho, I don't think namespaces is used like this in other languages. Also I don't believe I covered the topic completely but should give you an idea of what it is.
#2
09/03/2013 (5:50 pm)
the documentation says that serve to implement methods to a class, however encounter script code like this I do not understand.

$pref::Input::MouseEnabled = 1;
$pref::Input::LinkMouseSensitivity = 1;
$pref::Input::KeyboardEnabled = 1;
$pref::Input::KeyboardTurnSpeed = 0.1;
$pref::Input::JoystickEnabled = 0;

This leads me to a part of the documentation "Namespace List" that the true not understand.
#3
09/03/2013 (6:23 pm)
For global variable names you can use "namespace" formatting to help organize your information. These are global variables - see the $ in front?
#4
09/04/2013 (4:16 am)
For global variables it is just a way of identifying the variables. It doesn't have any specific function except for visual preference.
#5
09/04/2013 (10:54 am)
Well, I clarify the doubts about this, is that I feel like a escabador in the ruins of Egypt trying to decipher things.

That only works with Global variables?

Now please an example of this list.

docs.garagegames.com/torque-3d/reference/namespaces.html
#6
09/04/2013 (1:02 pm)
Those the default namespaces in the engine. It is telling you what is being used so you don't reuse or so you know about them. I would guess however that the list may not be all that is used.

The reason to use those namespaces is so you don't have naming collisions:
// user data
$filename = "user.dat";
...
<a bunch of code here, or even in a different file>
...
// server data
$filename = "server.dat";
Oh no! My data is all messed up!

// user data
$userdata::filename = "user.dat";
...
<a bunch of code here, or even in a different file>
...
// server data
$serverdata::filename = "server.dat";
Ahhh! My data is just fine.

Everything is logical and uses good variable names, but stuff is in separate "namespaces". The two namespaces are $userdata and $serverdata. The same is used for objects to separate object types and even object function.

$userobj = new ScriptObject(UserObject);

$serverobj = new ScriptObject(ServerObject);

function UserObject::onAdd(){
  echo("Added a UserObject");
}
function ServerObject::onAdd(){
  echo("Added a ServerObject");
}
Both have the same function, but they do not get mixed up because they are in different "namespaces".

So you call them like this:
$userobj.onAdd();
$serverobj.onAdd();

Of course if you are using globals then this would be better:
$userdata::object = new ScriptObject(UserObject);
$serverdata::object = new ScriptObject(ServerObject);

// then call
$userdata::object.onAdd();
$serverdata::object.onAdd();

comprende?
#7
09/04/2013 (5:38 pm)
www.egiptologia.com/images/stories/noticias/2012-03-12.jpg
Greatly appreciate the help, so I have an idea and slowly advance in understanding the script.