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?
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?
About the author
Owner of MK Development www.mkdevelopment.se
#2
I did used the global approach and discovered that I could use them pretty much as constants. For example this code works:
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.
Torque Owner Richard Ranft
Roostertail Games
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.