Game Development Community

Getting a variable

by Scooby Brown · in Technical Issues · 08/01/2008 (9:58 pm) · 2 replies

Ok fellow torquers, this is a very perplexing problem for me and i believe will help others around.
now after an hour of searching, i have yet found a way to do this.

its kind of hard for me to explain but,
I want to get a dynamic variable from an object using the variable passed into the function

for example


function ShapeBase::MountWeaponImage( %this, %weaponAmmoInClip, %slot, %curWeapon) <-- up here were %weaponAmmoInClip is passed in,
{
%curWeapon = %this.getMountedImage(%slot);
%playerObj = %this;

echo(%weaponAmmoInClip);
echo(%this.getDataBlock().getName());
echo(%playerObj.client.weaponammo.%weaponAmmoInClip); <-- i would like it to point to it here but i have no clue how

%ammoOnPile = %this.getInventory(%curWeapon.ammo);
%AltammoOnPile = %this.getInventory(%curWeapon.Altammo);

// Images assume a false ammo state on load.
// We need to set the state according to the current inventory.

if ((%playerObj.client.weaponammo.weaponAmmoInClip > 0) || (%ammoOnPile > 0))
{
%this.setImageAmmo(%slot,true);
}

%this.client.displayWeaponHUD(%curWeapon.getName());
%this.client.setClipAmountHud(%playerObj.client.weaponammo.weaponAmmoInClip);
%this.client.setAmmoAmountHud(%ammoOnPile);
%this.client.ShowWeaponReload( false );

}

Any help would be appreciated

#1
08/01/2008 (11:12 pm)
I don't remember the exact method name and I'm not at a computer with Torque installed, but its something like...
%obj.getFieldValue( %fieldName );

Search the documentation for getField, or getDataField, or getFieldValue... Its something like that and its a member of SimObject or ConsoleObject.
#2
08/02/2008 (12:14 pm)
Thank you very much i will try that