Struggling with tutorials from the torque 3D cookbook
by Nicole · in Torque 3D Beginner · 03/09/2014 (6:40 am) · 7 replies
Hi guys,
I'm a beginner at using torque 3D especially with the programming, I have purchased a book from the torque 3D on Amazon.
I got almost half way through the book but I'm currently struggling on chapter 1 of Creating a new SimObject instance and Creating a new internal name only SimObject instance.
I don't know whats it trying to ask me to do, if anyone be able to help me out, I would appreciate it, I have been struggling for good few hours and still couldn't get myself around it.
Many thanks,
I'm a beginner at using torque 3D especially with the programming, I have purchased a book from the torque 3D on Amazon.
I got almost half way through the book but I'm currently struggling on chapter 1 of Creating a new SimObject instance and Creating a new internal name only SimObject instance.
I don't know whats it trying to ask me to do, if anyone be able to help me out, I would appreciate it, I have been struggling for good few hours and still couldn't get myself around it.
Many thanks,
About the author
#2
In the chapter you are reading, it is using ScriptObject as an example. This is the simplest type of SimObject you can create in TorqueScript. It really doesn't do much, which is why it's a good example. All you need to do is open up a script file (*.cs) with a text editor, like Notepad or Torsion. This is creating an object in TS:
You can give it a unique name like this:
If you do the following, you will see its name in the console:
A special field is the InternalName. You can set that when you create the object:
In that case, calling getName() will return an empty string. But if you call getInternalName(), you will get "InternalObjectName".
Ultimately, that section in the book is instructing you on how to create a simple object in TorqueScript, set its fields, and access those fields. So what are you stuck on? How to open a script? How to edit it? The syntax of the code?
03/09/2014 (8:40 am)
@Nicole - What it's doing is telling you to create a new object in TorqueScript. When the book says create a new instance of a SimObject, it does not explicitly mean creating an object of the type "SimObject". SimObject is the parent class all objects exposed to TorqueScript derive from. A Player is a SimObject. A GuiControl is a SimObject. In the chapter you are reading, it is using ScriptObject as an example. This is the simplest type of SimObject you can create in TorqueScript. It really doesn't do much, which is why it's a good example. All you need to do is open up a script file (*.cs) with a text editor, like Notepad or Torsion. This is creating an object in TS:
%object = new ScriptObject();
You can give it a unique name like this:
%object = new ScriptObject(ObjectName);
If you do the following, you will see its name in the console:
%object = new ScriptObject(ObjectName); echo(%object.getName();
A special field is the InternalName. You can set that when you create the object:
%object = new ScriptObject([InternalObjectName]);
In that case, calling getName() will return an empty string. But if you call getInternalName(), you will get "InternalObjectName".
Ultimately, that section in the book is instructing you on how to create a simple object in TorqueScript, set its fields, and access those fields. So what are you stuck on? How to open a script? How to edit it? The syntax of the code?
#3
new Player(MyPlayer);
%pos = MyPlayer.getPosition();
setting the properties for new Player object like
new Player(MyPlayer)
{
datablock = SoldierDatablock;
position = "0 0 10";
size = "1 1 1";
squad = "Bravo";
};
new Player(MyPlayer2 : MyPlayer)
{
position = "2 0 10";
};
All this is under the section, Creating a new SimObject instance. All of the above, what is it instructing me to do?
In the section under Creating a new Internal name only SimObject instance, it provides a code:
%object = new ScriptObject([MyScriptObject]);
and also there are other codes:
new GuiWindowCtrl(MyDialog) {
... some properties here....
new GuiControl() {
internalName = "control1";
... some properties here ...
};
new GuiControl() {
internalName = "control2";
... some properties here ...
};
};
What is the above instructing me to do?
There is another section, Creating a new Datablock object:
Datablock StaticShapeData(MyShapeData)
{
category = "scenic";
shapeFile = "art/shapes/rocks/rock1.dts";
computeCRC = true;
isInvincible = true;
};
What is that part instructing me to do? And how do I do that?
Creating a new singleton, I also have trouble with that part as well, I don't fully understand what it is telling/instructing me to do.
It has provided the code but what do I do with that? Below is the code:
singleton Material(DECAL_scorch)
{
baseTex(0) = "./scorch_decal.png";
translucent = true;
translucentBlendOp = None;
translucentZWrite = true;
alphaTest = true;
alphaRef = 84;
};
What am I meant to do with that code? What is instructing me to do? Please can anyone provide assistance?
Many thanks,
03/09/2014 (10:35 am)
Michael: When I was looking down the page, it also mentioned:new Player(MyPlayer);
%pos = MyPlayer.getPosition();
setting the properties for new Player object like
new Player(MyPlayer)
{
datablock = SoldierDatablock;
position = "0 0 10";
size = "1 1 1";
squad = "Bravo";
};
new Player(MyPlayer2 : MyPlayer)
{
position = "2 0 10";
};
All this is under the section, Creating a new SimObject instance. All of the above, what is it instructing me to do?
In the section under Creating a new Internal name only SimObject instance, it provides a code:
%object = new ScriptObject([MyScriptObject]);
and also there are other codes:
new GuiWindowCtrl(MyDialog) {
... some properties here....
new GuiControl() {
internalName = "control1";
... some properties here ...
};
new GuiControl() {
internalName = "control2";
... some properties here ...
};
};
What is the above instructing me to do?
There is another section, Creating a new Datablock object:
Datablock StaticShapeData(MyShapeData)
{
category = "scenic";
shapeFile = "art/shapes/rocks/rock1.dts";
computeCRC = true;
isInvincible = true;
};
What is that part instructing me to do? And how do I do that?
Creating a new singleton, I also have trouble with that part as well, I don't fully understand what it is telling/instructing me to do.
It has provided the code but what do I do with that? Below is the code:
singleton Material(DECAL_scorch)
{
baseTex(0) = "./scorch_decal.png";
translucent = true;
translucentBlendOp = None;
translucentZWrite = true;
alphaTest = true;
alphaRef = 84;
};
What am I meant to do with that code? What is instructing me to do? Please can anyone provide assistance?
Many thanks,
#4
Please keep in mind I am in no way condescending. Every question I ask is sincere and has a goal of helping you. Some questions are going to seem very basic, but it's my way of getting you to a solution properly.
First, do you understand what scripting is? Do you know how to create, edit, and run a script, with the intention of seeing the results?
03/09/2014 (4:27 pm)
Ok, so it seems we should start at the very beginning before tackling each coding exercise. This will be a useful dialog for Torque 3D and Torque 2D users alike. Please keep in mind I am in no way condescending. Every question I ask is sincere and has a goal of helping you. Some questions are going to seem very basic, but it's my way of getting you to a solution properly.
First, do you understand what scripting is? Do you know how to create, edit, and run a script, with the intention of seeing the results?
#5
I know how to open the script (.cs) file but not sure how you create, edit and run a script though. I know that you can use Torque 3D game engine and press the "@" key on the keyboard to open up the console to run a specific function
03/09/2014 (4:33 pm)
I'm guessing scripting is a programming language that is interpreted by another programI know how to open the script (.cs) file but not sure how you create, edit and run a script though. I know that you can use Torque 3D game engine and press the "@" key on the keyboard to open up the console to run a specific function
#6
When you want to modify the source code, you have to use a program like Visual Studio. This is a C compiler which can interpret C++ and generate the .exe file. TorqueScript does not require a compiler. You edit the text in the file, then Torque will read the script files and run their instructions at runtime.
Because Torque handles the reading and interpretation of TorqueScript, you do not need a specialized program to edit .cs files. You can use programs like Notepad, Notepad++, and Torsion. Torsion is the most popular editor, since it was built specifically for creating, editing, and debugging TorqueScript files.
Now, the chapters in the book are having you dive into editing TorqueScript files. The book is excellent, as it is written by probably the most knowledgeable Torque 3D developer you can find. What I can post would be considered quick reference material. These are the docs I wrote about TorqueScript:
TorqueScript Introduction
TorqueScript Syntax
TorqueScript Quick Reference
Read through those three links. Don't skip around, especially on the first two links. Once you've done that, reply to this thread and I can point you to the next steps.
03/09/2014 (5:57 pm)
Ok, so that helps a bit. Let me clear up some details for you. Scripting is a kind of programming, not a language. Torque consists of two programming components. There's the source code which is written in C++ and must be compiled. Then there's TorqueScript, which is a proprietary scripting language that does not have to be compiled. C++ is one language, TorqueScript is another language. Both share similarities, since they are both based on C. In fact, the .cs extension is short for "C Script". When you want to modify the source code, you have to use a program like Visual Studio. This is a C compiler which can interpret C++ and generate the .exe file. TorqueScript does not require a compiler. You edit the text in the file, then Torque will read the script files and run their instructions at runtime.
Because Torque handles the reading and interpretation of TorqueScript, you do not need a specialized program to edit .cs files. You can use programs like Notepad, Notepad++, and Torsion. Torsion is the most popular editor, since it was built specifically for creating, editing, and debugging TorqueScript files.
Now, the chapters in the book are having you dive into editing TorqueScript files. The book is excellent, as it is written by probably the most knowledgeable Torque 3D developer you can find. What I can post would be considered quick reference material. These are the docs I wrote about TorqueScript:
TorqueScript Introduction
TorqueScript Syntax
TorqueScript Quick Reference
Read through those three links. Don't skip around, especially on the first two links. Once you've done that, reply to this thread and I can point you to the next steps.
#7
03/10/2014 (5:47 am)
Now that you've read that, check out these very simple TorqueScript tutorials. If you are able to get that working, the next step would be the guided FPS tutorial found here. I believe with the links I've posted and re-reading the chapters in the T3D Cookbook, you should be able to script on your own. Please reply if something is unclear.
Andrew Mac