Misc. little things
by Vern Jensen · in Torque Game Builder · 09/09/2006 (12:21 am) · 2 replies
I'm curious about a few miscellaneous little things:
1) Is it possible to define a constant in TorqueScript, or do you just set up a global variable to act like your constant? Currently I'm using stuff like
$kMainSpriteLayer = 4;
for my "constants".
2) I understand TorqueScript converts between true/false and 1/0. So you can set:
%myValue = false;
and then do
if (!%myValue)
whatever();
Is this slower than just doing this?
%myValue = 0;
Normally it wouldn't matter, but let's say you're doing lots of code like this from inside a timer that's called every 20 milliseconds, and you have lots of these timers. Now it matters a little.
3) We're supposed to avoid putting too much in the onSceneUpdate() callback, but the Mini Platform tutorial puts lots of stuff in here, and in fact you'd have to expand this quite a bit if you wanted to add enemies to the platformer too.
So the question: would it be better to make a game that had a lot of stuff in onSceneUpdate(), or a game that had lots of individual timers for each sprite? The advantage with timers is that you could limit them all to say 60fps, vs. onSceneUpdate() which is called as fast as possible, but is there overhead to having lots of timers, vs. just one onSceneUpdate() function call?
1) Is it possible to define a constant in TorqueScript, or do you just set up a global variable to act like your constant? Currently I'm using stuff like
$kMainSpriteLayer = 4;
for my "constants".
2) I understand TorqueScript converts between true/false and 1/0. So you can set:
%myValue = false;
and then do
if (!%myValue)
whatever();
Is this slower than just doing this?
%myValue = 0;
Normally it wouldn't matter, but let's say you're doing lots of code like this from inside a timer that's called every 20 milliseconds, and you have lots of these timers. Now it matters a little.
3) We're supposed to avoid putting too much in the onSceneUpdate() callback, but the Mini Platform tutorial puts lots of stuff in here, and in fact you'd have to expand this quite a bit if you wanted to add enemies to the platformer too.
So the question: would it be better to make a game that had a lot of stuff in onSceneUpdate(), or a game that had lots of individual timers for each sprite? The advantage with timers is that you could limit them all to say 60fps, vs. onSceneUpdate() which is called as fast as possible, but is there overhead to having lots of timers, vs. just one onSceneUpdate() function call?
Torque Owner Thomas Buscaglia
1) To my knowlege, there are no constant variables in TorqueScript.
2) Your cs files are compiled before they are actually executed and the 'false' keyword just evaluates to 0. Basically, it's a matter of preference and holds no performance implications. I prefer to use 'true' and 'false' to remind myself that I am dealing with what I intend to be a boolean field.
3) There is really no right answer to this question because different games can have drastically different needs. In the case of many games, you will inevitably run into severe roadblocks if you don't update the player's physics every scene update because all sorts of things can change every frame.
Consider in a platformer the case when the player is landing on a very slight slope: the player might appear to slide down the slope at first when that might not be intended because the velocity is not being explicitly modified until several frames later.
There are, however, many cases where you don't need that much precision and a timer might be more appropriate. There are still other cases when you only need to update an object's physics when certain events occur. In this case, updating the physics in onUpdateScene would be a big waste of resources.
I hope this was helpful.