Trouble setting new values in a datablock [SOLVED]
by Luis E Pabon · in Torque 3D Professional · 06/09/2011 (1:50 pm) · 4 replies
I am trying to set certain custom values inside player datablocks, but for some reason they don't seem to work.
This is an example of the datablock:
If I then run this code:
I only get "" when checking %player.isEnemy or %player.shootingDelay
Is there something I'm missing here? Do I need to use the onAdd function to give the datablock new values?
This is an example of the datablock:
datablock PlayerData(DemoPlayer : DefaultPlayerData)
{
shootingDelay = 2000;
isEnemy = false;
};If I then run this code:
%player = new AiPlayer()
{
dataBlock = DemoPlayer;
path = "";
};I only get "" when checking %player.isEnemy or %player.shootingDelay
Is there something I'm missing here? Do I need to use the onAdd function to give the datablock new values?
About the author
#2
06/09/2011 (2:05 pm)
Off the top of my head I think you would need %player.getDataBlock().isEnemy;
#3
Now, I 'think' there is already a variable in the player datablock called 'isAIControlled'[or something similar].....that may work with your first calling....%player.isEnemy, by doing something like, %player.isAIControlled = true;
I think this calling checks to see if the object is derived from a AIPlayer object, which Torque engine AI are...;) Might be why the original coders kept this variable in...doesn't do anything in C++ code[if I'm not mistaken] just a nice flag ready to be used.....;)!
But I am a lowly artist who hacks his way thru scripting....add some NaCl to these words to taste.
Good luck!
06/10/2011 (5:31 am)
Yes, you added a dynamic variable[isEnemy] to the datablock, which the engine doesn't 'know' about, yet....until the script is compiled and run.Now, I 'think' there is already a variable in the player datablock called 'isAIControlled'[or something similar].....that may work with your first calling....%player.isEnemy, by doing something like, %player.isAIControlled = true;
I think this calling checks to see if the object is derived from a AIPlayer object, which Torque engine AI are...;) Might be why the original coders kept this variable in...doesn't do anything in C++ code[if I'm not mistaken] just a nice flag ready to be used.....;)!
But I am a lowly artist who hacks his way thru scripting....add some NaCl to these words to taste.
Good luck!
#4
Most of my previous scripting has been in TGB, where things work slightly differently. Gotta lose some bad habits I guess.
06/10/2011 (10:02 am)
Thanks for the replies! :)Most of my previous scripting has been in TGB, where things work slightly differently. Gotta lose some bad habits I guess.
Torque 3D Owner Luis E Pabon
Independent