Day one programming questions for TGB
by Mike Horan · in Technical Issues · 10/06/2008 (4:36 pm) · 3 replies
Hey all,
I've been working with the free TGB demo for a few days, and I'm learning a lot, but I have some basic questions. I'm sure these will pose no challenge for the more experienced element, and since GG has this incredible online community, I thought I'd take it out for a spin...
In the edit tab, what is the point of the behaviors rollout? If you're having to script the behaviors into the individual .cs file, doesn't having to go back into TGB and "adding" them in the rollout just add another step? Conversely, if you were to "add" a specific behavior to more than one thing, each would have to have the correct code in their file, right?
How restricted is the behavior scripting? If you're adding an exec command into your main.cs file telling it to execute your player.cs info, does it matter what order that code is in in the player.cs file?
For example, everyone is familiar with the "Fish" game tutorial. The first thing you do in the player.cs file is bind the keys for "up," "down," "left," and "right." The next thing you do is set the linear velocity for each of those functions. Must they be done in this order? How much wiggle room is there?
What's to stop you from just scripting everything into you main.cs file?
Thanks. I hope these aren't too painful. Someone once told me, "ask a stupid question and you just might learn something."
I've been working with the free TGB demo for a few days, and I'm learning a lot, but I have some basic questions. I'm sure these will pose no challenge for the more experienced element, and since GG has this incredible online community, I thought I'd take it out for a spin...
In the edit tab, what is the point of the behaviors rollout? If you're having to script the behaviors into the individual .cs file, doesn't having to go back into TGB and "adding" them in the rollout just add another step? Conversely, if you were to "add" a specific behavior to more than one thing, each would have to have the correct code in their file, right?
How restricted is the behavior scripting? If you're adding an exec command into your main.cs file telling it to execute your player.cs info, does it matter what order that code is in in the player.cs file?
For example, everyone is familiar with the "Fish" game tutorial. The first thing you do in the player.cs file is bind the keys for "up," "down," "left," and "right." The next thing you do is set the linear velocity for each of those functions. Must they be done in this order? How much wiggle room is there?
What's to stop you from just scripting everything into you main.cs file?
Thanks. I hope these aren't too painful. Someone once told me, "ask a stupid question and you just might learn something."
About the author
#2
Question #1: What's the point of the behaviors rollout and how do they work?
The behaviors rollout is a very useful way to add behaviors to your objects. When you create a new behavior, you give it a name and type. The behavior rollout uses this information to organize all your behaviors for easier use. All you have to do to create a new behavior is type this:
somewhere in a file which is executed at runtime. Once Torque creates a new behavior, it lists that behavior in the behaviors rollout for you to add to as many objects as you like. So, 'no' you don't need to create multiple types of the same behavior. Just create one, have Torque execute the file that it's in, and you will be able to assign it to any object you like. I generally like to create a "behaviors.cs" file in which I define all the different behaviors I'll use in my game. I then have it executed in my main.cs file.
Question #2: How much wiggle room do you have when scripting?
Well, let me say, "I don't exactly know." However, I'll also say it must be a lot because I've never had many (if any) problems with function ordering. As far as functions are concerned, it doesn't seem to matter where you put them, as long as the file they are in is executed. I'm not sure if declarations are that way, too, but I usually execute the files that declare a variable before I execute the files that use it. For example, if I made a menu and wanted to modify how it works in script, I would execute the .gui file in which it was declared before I executed the .cs file in which I wrote its scripting code.
Question #3: What would keep you from scripting everything in your main.cs file?
As far as I know, nothing. You could just as easily write everything in your .cs files in the place of their corresponding exec commands, as keep them separate--it should work the same. The ability to create .cs files and execute them is there for organization and ease of use. The main.cs file which would result from adding all your .cs files to it would be just plain torture to edit.
Hope that was helpful!
Have fun!
EDIT: Sorry, I guess Michael was posting at the same time I was.
10/06/2008 (6:57 pm)
Hi Mike,Question #1: What's the point of the behaviors rollout and how do they work?
The behaviors rollout is a very useful way to add behaviors to your objects. When you create a new behavior, you give it a name and type. The behavior rollout uses this information to organize all your behaviors for easier use. All you have to do to create a new behavior is type this:
if(!isObject(testBehavior))
{
%temp = new BehaviorTemplate(testBehavior);
....and then you use %temp to assign behavior fields and describe your new description
}somewhere in a file which is executed at runtime. Once Torque creates a new behavior, it lists that behavior in the behaviors rollout for you to add to as many objects as you like. So, 'no' you don't need to create multiple types of the same behavior. Just create one, have Torque execute the file that it's in, and you will be able to assign it to any object you like. I generally like to create a "behaviors.cs" file in which I define all the different behaviors I'll use in my game. I then have it executed in my main.cs file.
Question #2: How much wiggle room do you have when scripting?
Well, let me say, "I don't exactly know." However, I'll also say it must be a lot because I've never had many (if any) problems with function ordering. As far as functions are concerned, it doesn't seem to matter where you put them, as long as the file they are in is executed. I'm not sure if declarations are that way, too, but I usually execute the files that declare a variable before I execute the files that use it. For example, if I made a menu and wanted to modify how it works in script, I would execute the .gui file in which it was declared before I executed the .cs file in which I wrote its scripting code.
Question #3: What would keep you from scripting everything in your main.cs file?
As far as I know, nothing. You could just as easily write everything in your .cs files in the place of their corresponding exec commands, as keep them separate--it should work the same. The ability to create .cs files and execute them is there for organization and ease of use. The main.cs file which would result from adding all your .cs files to it would be just plain torture to edit.
Hope that was helpful!
Have fun!
EDIT: Sorry, I guess Michael was posting at the same time I was.
#3
Just to clear up, I think I was substituting the concept of "behaviors" for many different things that would require scripting, in addition to 'actual' behaviors. Since (it seemed) I was adding something in script to every file I ended up using the behavior rollout to apply, I thought it seemed redundant. But now I get the picture. The behavior rollout works just like it should!
As for the other questions about scripting things in order, (or just shoving them all in the main.cs file) it was a curiosity that I had a hunch about. Staying organized and migraine-free are good enough reasons for me.
Thanks again!
Mike
10/07/2008 (5:34 pm)
Thank you both, guys. I really appreciate you taking the time. It makes a lot more sense.Just to clear up, I think I was substituting the concept of "behaviors" for many different things that would require scripting, in addition to 'actual' behaviors. Since (it seemed) I was adding something in script to every file I ended up using the behavior rollout to apply, I thought it seemed redundant. But now I get the picture. The behavior rollout works just like it should!
As for the other questions about scripting things in order, (or just shoving them all in the main.cs file) it was a curiosity that I had a hunch about. Staying organized and migraine-free are good enough reasons for me.
Thanks again!
Mike
Employee Michael Perry
ZombieShortbus
"What is the point of the behaviors rollout? (...)"
Answer - When you write a behavior in script, and save it to the behaviors folder, you are making that behavior globally available to your editor. This means you can apply the behavior to any scene object. The rollout behavior how you apply a behavior, just as you would apply a name, position, or layer. The second part (the conversely section) has me confused:Could you rephrase this, as I don't really know what you mean.
The coding that goes into player.cs for the fish tutorial is way different than behavior creation.
As far as what code should come first, for your particular example in the fish game it does not really matter which comes first (binding functions or linear velocity functions). It would make sense to keep the methods grouped together based on functionality, but it's not absolutely required.
A massive migraine and temporary insanity. Want me to go into details? =)
Did any of these answers make sense?