Game Development Community

Is it possible to define constants? [solved]

by Max Kielland · in Torque Game Builder · 01/16/2013 (6:10 am) · 4 replies

Hi,

Is it possible to define constants (like in C/C++). I guess I can declare global variables to hold my state machine values but wouldn't that slow down the script?


#1
01/16/2013 (9:58 am)
Not really - the engine uses globals as "constants" all the time; just don't change the value....

You can add them from the C++ side though - just expose a console variable with logic in the setter to only allow the value to be set once, or make it an actual const variable and expose it.
#2
01/16/2013 (10:02 am)
Okay, thanks.

I did used the global approach and discovered that I could use them pretty much as constants. For example this code works:

$kGoodsState_Position = 0;
$kGoodsState_Enter    = 1;
$kGoodsState_Transit  = 2;
$kGoodsState_Exit     = 3;

switch(%this.State) {
    
  case $kGoodsState_Position :

  case $kGoodsState_Enter :

  case $kGoodsState_Transit :

  case $kGoodsState_Exit :

}
#3
01/16/2013 (12:55 pm)
In order to clarify things you could name them something like this:
$Constant::GoodState_Position = 0;
$Constant::GoodState_Enter = 1;
$Constant::GoodState_Transit = 2;
$Constant::GoodStatt_Exit = 3;
or some other scheme. Helps keep things organized and identifiable.
#4
01/16/2013 (12:58 pm)
Good point!
I will use this solution :)

Thank you.