Game Development Community

Getting at variables in the script from the engine

by Owen "WDA" Ashcroft · in Torque Game Engine · 07/15/2002 (4:00 pm) · 2 replies

I am currently trying to retrieve a variable from the script.

I have added to the %p in the crossbow.cs an extra variable:
// Create the projectile object
   %p = new (%this.projectileType)() {
      dataBlock        = %projectile;
      initialVelocity  = %muzzleVelocity;
      initialPosition  = %obj.getMuzzlePoint(%slot);
      sourceObject     = %obj;
      sourceSlot       = %slot;
      client           = %obj.client;
      generalModifier  = %modifier; //new variable
   };
Like this
I have then added a mGeneralModifier to the projectile.cc in the form of:
Projectile::Projectile()
{
   // Todo: ScopeAlways?
   mNetFlags.set(Ghostable);
   mTypeMask |= ProjectileObjectType;

   mCurrPosition.set(0, 0, 0);
   mCurrVelocity.set(0, 0, 1);

   mSourceObjectId = -1;
   mSourceObjectSlot = -1;
   mGeneralModifier = 1; //default value (I assume)

   mCurrTick         = 0;

   mParticleEmitter   = NULL;

   mProjectileShape   = NULL;
   mActivateThread    = NULL;
	mMaintainThread    = NULL;

   mHidden           = false;
   mFadeValue        = 1.0;
}
I have then added:
void Projectile::initPersistFields()
{
   Parent::initPersistFields();

   addField("initialPosition",  TypePoint3F, Offset(mCurrPosition, Projectile));
   addField("initialVelocity", TypePoint3F, Offset(mCurrVelocity, Projectile));
   addField("sourceObject",     TypeS32,     Offset(mSourceObjectId, Projectile));
   addField("sourceSlot",       TypeS32,     Offset(mSourceObjectSlot, Projectile));
   addField("generalModifier",	TypeF32,	Offset(mGeneralModifier, Projectile)); //Added
  
}
Which from stuff like initialPosition appears to pull values in from the script, but obviously doesn't! as in Projectile::processTick where it emits particles the value for mGeneralModifier is the default of 1, could anyone shed some light on this (oh I declard it in the projectile.h as well as part of the structure).

Owen

#1
07/15/2002 (5:26 pm)
You need to send the information through the network protocal using packData and unPackData.

If you look for these two functions in the ProjectileData class you'll see what I mean.
#2
07/15/2002 (6:23 pm)
Thanks, after some playing I had to add to PackUpdate not PackData but it all works.

Thanks!