Game Development Community

Math/GUI functions in T2D

by Daniel Huffman · in Torque Game Builder · 05/17/2005 (10:35 pm) · 4 replies

Hello all, I just bought this engine not two days ago, just to mess around with it a bit. I'm very new to game design and programming as well, so maybe getting an Early Adopter version was a mistake. Oh well, the fun is in the learning sometimes. I was wondering, are the math operators different from C/C++? I have, for instance, a desire to get the remainder of a division. Is there some sort of special modulus function for TorqueScript, or is it just div(x,y)? Is sqrt() something different? Is there some sort of resource for TorqueScript functions (particularly math functions, if they are indeed different) that I can access, as I am not allowed into the documentation appendices? (I guess that documentation is for TGE licensees, not T2D licensees.) Is there a value that created variables always default to?

Also, how does one get a value from a TextEdit box from the GUI?

I'm trying to put together a simple hex-based Risk-type game, not quite the same but similar, either as a standalone fun project to learn the ropes or as a building block to something else (also to learn the ropes, of course). The math functions are for the randomized starting map (maybe for the AI, haven't even thought of that since I just started about a couple hours ago, so no idea). I already have the map generation system done in concept and started in C, but it will need new functions if the math functions are different. I guess I can use Replace in the worst case scenario. The GUI question is just something I would like to know. I've been looking at programming of some sort off and on as a hobby for a while now, but was always massively intimidated by interfacing with graphics. T2D looks amazingly simple (yet not simplistic) compared to, you know, just going from C or C++. I'm kind of excited, and have already had some fun, although I'm not really even doing anything that uses T2D yet.

About the author

Recent Threads


#1
05/17/2005 (11:04 pm)
"Also, how does one get a value from a TextEdit box from the GUI?"

guicontrolname.getValue();

if it was named "TextBox"... you could do this

%test = textBox.getValue();
echo(%test);
#2
05/18/2005 (2:47 am)
You'll probably have to look over the torque script resources for a full command list, I know there is a resource that covers it, I just can't remember what it was called.

To get you going though, the basic operators are pretty much the same, e.g
+, -, *, /, %

The maths functions are similar, but they all have an "m" prefixed, e.g

mCos(), mSin(), mTan(), mAbs(), mPow(), mSqrt(), mCeil(), mFloor() etc

If you open up the engine/math/consoleFunctions.cc file you will see each maths function that is exposed in script.
#3
05/18/2005 (5:03 pm)
Thank you both very much, especially you Mr. Langley. I very much enjoyed your tutorials.

EDIT: I'm still having trouble trying to find a function that will return to me a remainder. Anyone know?
EDIT2: Nevermind, there is a very easy solution, just using the floor function and subtracting that from the quotient and multiplying by the divisor.
#4
05/19/2005 (3:12 am)
Also, the '%' operator will return a remainder e.g.
echo( 13 % 5 );
will give the answer 3.
BUT... it's behaviour for negative numbers is strange (wrong!)