I'm confused how to organize scripts!
by Alessandro · in Torque 3D Beginner · 09/25/2011 (1:47 pm) · 10 replies
Hello,
I spent some time making scripting tests, to learn and discover the better way to achieve some jobs.
Now I have a serious problem: I'm really confused how to start to write scripts for my game.
There are many scripts directories, many script files, etc...
I red the documentation but... but... my mind is still confused for some points :-(
These are my problems:
1) When do I write scripts in "core" directory?
2) When I define some keys (keyboard) they often conflict with built-in key assignments. Even if the environment integration between design-time and runtime is nice, sometimes it is confusing, since I cannot divide them. For example, I found scripts to manage design time user interface, and sometimes my scripts risk to go in conflict with those interfaces.
Usually I make programs (and games) thinking to a blank environment, instead in Torque I have the feeling that I'm working on a game-mod (not inside an independent game engine).
Please can you give me some hints about...
1) How to configure my keys (where? in which files? HOw to avoid conflict with keys in Torque design time?)
2) How to organize scripts (client side... server side... etc....)
More hints?
Thank you in advance for your help!!
I spent some time making scripting tests, to learn and discover the better way to achieve some jobs.
Now I have a serious problem: I'm really confused how to start to write scripts for my game.
There are many scripts directories, many script files, etc...
I red the documentation but... but... my mind is still confused for some points :-(
These are my problems:
1) When do I write scripts in "core" directory?
2) When I define some keys (keyboard) they often conflict with built-in key assignments. Even if the environment integration between design-time and runtime is nice, sometimes it is confusing, since I cannot divide them. For example, I found scripts to manage design time user interface, and sometimes my scripts risk to go in conflict with those interfaces.
Usually I make programs (and games) thinking to a blank environment, instead in Torque I have the feeling that I'm working on a game-mod (not inside an independent game engine).
Please can you give me some hints about...
1) How to configure my keys (where? in which files? HOw to avoid conflict with keys in Torque design time?)
2) How to organize scripts (client side... server side... etc....)
More hints?
Thank you in advance for your help!!
#2
Thank you!
09/25/2011 (3:54 pm)
I'm reading it and seems very good! A nice hint to get a quick startup!Thank you!
#3
The "core" folder is a bit of a left over from older versions of the engine. Which leaves "art" and "scripts" being split between things pertaining to actual art objects and things which are purely script ...
eg: art/datablocks/aiplayer.cs <-- the datablock reference for the models and all of it's physcial variables in-game
eg: scripts/server/aiplayer.cs <-- the scripts for powering the stock Ai "think" function.
09/26/2011 (7:11 am)
Files that are exec'd work from any address under the "game" directory. Check out "scripts/client/init.cs"The "core" folder is a bit of a left over from older versions of the engine. Which leaves "art" and "scripts" being split between things pertaining to actual art objects and things which are purely script ...
eg: art/datablocks/aiplayer.cs <-- the datablock reference for the models and all of it's physcial variables in-game
eg: scripts/server/aiplayer.cs <-- the scripts for powering the stock Ai "think" function.
#4
09/26/2011 (10:12 am)
The "core" is those scripts that were thought to be useful but non-specific for every game. Game scripts are simply a "mod" that extends and/or overrides the core. This setup was done to keep from having to duplicate the same code for each and every project. However, over time the core has gotten bloated and even contains some game specific code. If you leave the core alone you can organize everything else however you wish. If you're willing to make a few source code changes you can even merge the core into your own directory structure.
#6
if you open the "main.cs" you will see "onStart()" then...
exec("./client/init.cs");
exec("./server/init.cs");
Inside those scripts there are a plethora of scripts exec().
So, where my code (my exec() to include my code) should be inserted to make the things good?
I created my subdir to include all my code, then I will create some classes. They will need startup, finalization, and events management.
So...?
09/26/2011 (2:56 pm)
Another question:if you open the "main.cs" you will see "onStart()" then...
exec("./client/init.cs");
exec("./server/init.cs");
Inside those scripts there are a plethora of scripts exec().
So, where my code (my exec() to include my code) should be inserted to make the things good?
I created my subdir to include all my code, then I will create some classes. They will need startup, finalization, and events management.
So...?
#7
Assuming a Template build:
You could also add your custom directory as a user directory (see the root main.cs for $userDirs) and by including a main.cs inside of it that would be responsible for loading and initializing the contents of your custom code. The loadDir() function in the root main.cs simply auto executes any main.cs file located in add-on or mod directories.
Complex answer
Everything can be changed to your discretion.
09/26/2011 (3:25 pm)
Simple answerAssuming a Template build:
- For client *side* scripts continue to use "scripts/client/init.cs".
- For server *side* scripts, generally you would use "scripts/server/scriptExec.cs"
You could also add your custom directory as a user directory (see the root main.cs for $userDirs) and by including a main.cs inside of it that would be responsible for loading and initializing the contents of your custom code. The loadDir() function in the root main.cs simply auto executes any main.cs file located in add-on or mod directories.
Complex answer
Everything can be changed to your discretion.
#8
For example: When user press a key, I need to react in some way. For example: user press "V" and I need to create a new model instance. So, how do I organize script? I think key press should be putted in CLIENT, but model instance should go in SERVER (since every player will have to see that new model). How can I do to let client scripts and server scripts communicate?!
Thank you!
10/07/2011 (4:18 am)
Does it mean that I can make my game inside a custom directory, without using CLIENT or SERVER dir?For example: When user press a key, I need to react in some way. For example: user press "V" and I need to create a new model instance. So, how do I organize script? I think key press should be putted in CLIENT, but model instance should go in SERVER (since every player will have to see that new model). How can I do to let client scripts and server scripts communicate?!
Thank you!
#9
10/07/2011 (4:46 am)
Quote:Yes. Game files go under "game" directory. That is all.
Does it mean that I can make my game inside a custom directory, without using CLIENT or SERVER dir?
#10
10/07/2011 (7:19 am)
Just remember to exec your script files wherever you place them.
Torque 3D Owner Hans Cremers
He posted a part of the draft version of the tutorial that comes with torque 3D.
Here is a link to the draft:
static.garagegames.com/static/pg/education/IntroductionToScripting.pdf
I hope that after reading it will all make sense :-)