Game Development Community

Static Persistant Fields

by William Todd Scott · in Torque Game Engine · 02/02/2006 (8:32 pm) · 2 replies

Hi All,

I have a custom shape object that has fields that are accessible via script. Some of the data members are static and thus effect every object. I made one of the static data members accessible via script. My hope is that the user can select one of the objects in the mission editor and change some of these class wide static data members. However, when I change the field in script it only appears to be changed on the one object....wierd.

Here are the code snippets:

In initPersistFields():
addGroup("Global Forest Settings");
addField("dropToBillboard", TypeBool, Offset(s_bDropToBillboard, CSpeedTreeWrapper));
endGroup("Global Forest Settings");

In packUpdate():
stream->writeFlag(s_bDropToBillboard);

In unPackUpdate():
s_bDropToBillboard = stream->readFlag();

Do I need to handle this field differently because it is static?

Thanks
Todd

#1
02/02/2006 (9:13 pm)
Your only real option to have data that is going to change across an entire set of instantiated objects of a class and also be dynamic (able to be changed in runtime like it sounds you need) is to use the ::consoleInit() method of your class, and tie it to a global variable (in c++) instead of a class member variable.

You would then need to have your objects refer to the global variable in their various class implementations.

An example of this would be something like the sRenderMyPlayer global variable for the Player class (implemented in Player.cc), and it's corresponding mapping to pref::Player::renderMyPlayer in Player::consoleInit().
#2
02/02/2006 (9:18 pm)
Thanks Stephen!

Todd