Game Development Community

Requesting help #1# script error found

by Airianna Williams · in Torque Game Engine · 02/13/2007 (8:24 pm) · 4 replies

I have a tad bit of a problem, and can not understand why I am having difficulties other than "I can't program" tho I am at least gonna try... I have been at this same pice of script for a week, and can not for the life of me figure it out on my own, I get a script error...

## ## $intelligance = 10; .... I can not see a reason for this scripting error, I even tried all my veriables with % signs, to no avail... Added every variable into the () with (PlayerBody)...

datablock PlayerData(PlayerBody)
{
$strength = 10; // These 6 stats will get modifiers to them later within game by the player...
$intelligance = 10; // every so often they will gain one additional stat point...
$wisdom = 10;
$dexterity = 10;
$constitution = 10;
$charisma = 10;
$statDamage = $constitution * 2;
$statEnergy = $intelligence + $wisdom + $constitution;
$statRepair = $statEnergy / 1000;
$statEPDP = $constitution / 10;
$statRecharge = $statEnergy / 1000;
$statForce = $strength / 1000 + 8.3;
$statEnergyDrain = .25 - $constitution / 1000;
$statRunEnergy = .35 - $constitution / 1000;
$statFSpeed = $strength / 1000 + 14.3;
$statBSpeed = $strength / 1000 + 8.3;
$statSideSpeed = $strength / 1000 + 8.4;
$enderFirstPerson = false;
shapeFile = "~/data/shapes/player/player.dts";

maxDamage = $statDamage;
maxEnergy = $statEnergy;
repairRate = $statRepair;
energyPerDamagePoint = $statEPDP;

rechargeRate = $statRecharge;

runForce = $statForce * 90;
runEnergyDrain = $statEnergyDrain;
minRunEnergy = $statRunEnergy;
maxForwardSpeed = $statFSpeed;
maxBackwardSpeed = $statBSpeed;
maxSideSpeed = $statSideSpeed;

maxUnderwaterForwardSpeed = $statFSpeed - 6;
maxUnderwaterBackwardSpeed = $statBSpeed - 7;
maxUnderwaterSideSpeed = $statSideSpeed - 7;

$statJump = $strength + $dexterity / 1000 + 8.4;
$statJumpDrain = 5 - $constitution / 1000;
$statMJumpDrain = 15 - $statJumpDrain;

jumpForce = $statJump * 90;
jumpEnergyDrain = $statJumpDrain;
minJumpEnergy = $statMJumpDrain;
jumpDelay = 8;

recoverDelay = 9;
recoverRunForceScale = 1.2;

minImpactSpeed = 45;
speedDamageScale = 0.4;

boundingBox = "1.2 1.2 2.3";
pickupRadius = 0.75;

boxNormalHeadPercentage = 0.83;
boxNormalTorsoPercentage = 0.49;
boxHeadLeftPercentage = 0;
boxHeadRightPercentage = 1;
boxHeadBackPercentage = 0;
boxHeadFrontPercentage = 1;

$statSurfaceAngle = $dexerity / 100 + 55;
$statJumpAngle = $statAngle * 2;
$statJump = $strength / 1000 + 20;

runSurfaceAngle = $statSurfaceAngle;
jumpSurfaceAngle = $statJumpAngle;

minJumpSpeed = $statJump * 90 / 10;
maxJumpSpeed = $statJump * 90 / 30;

horizMaxSpeed = 68;
horizResistSpeed = 33;
horizResistFactor = 0.35;

upMaxSpeed = 80;
upResistSpeed = 25;
upResistFactor = 0.3;

groundImpactMinSpeed = 10.0;
groundImpactShakeFreq = "4.0 4.0 4.0";
groundImpactShakeAmp = "1.0 1.0 1.0";
groundImpactShakeDuration = 0.8;
groundImpactShakeFalloff = 10.0;

};

#1
02/13/2007 (9:24 pm)
It's a valid error.

You're trying to store a global (dynamic) field (with its corresponding value) in a static datablock.

Datablocks aren't designed to store dynamic values, do a search on this site and you'll find a more graceful (and network friendly) solution to your problem.

If you want to do it your way (which I don't recommend) store your values like this:

function loadStats()
{
   $strength     = 10;
   $intelligence = 10;
   $wisdom       = 10;
   $dexterity    = 10;
}

datablock PlayerData(PlayerBody)
{
   strength     = $strength;
   intelligence = $intelligence;
   wisdom       = $wisdom;
   dexterity    = $dexterity;
// etc etc
};

PS 'intelligance' is spelt with an 'e' and not an 'a' - 'Intelligence'

Edit: Just FYI, your script contains more than 1 error, Torque just stopped on the first one it found.
#2
02/14/2007 (6:36 am)
Thank you for your assistance.

Since I am learning how to script, And have ideas within my head. And Will definantly be looking for a better sollution to my problem, Tho for right now, it just has to work. ANd I know, every variable I added is considered an error. Then it goes to the next function / block/ file...

(It looks like I could use the adventure pack to help me out in this area, as well as the programers guides...)

PS: while writing a script, spelling is case sensative for variables... And without you pointing that out, I would not have noticed I spelled it corrctly further down.

(Note to self)
Do NOT add a variable to data blocks, as this will be an error in the game, and the rest of the block will be skipped, if not the entire file.
#3
02/14/2007 (10:01 am)
The underlying topic you are confusing is the difference between variables (local or global), and fields.

--variables: independent storage for data that is not directly associated with a particular instance of an object. Can be local or global in scope, and uses a $ (global) or a % (local) to indicate scope.

$intelligence = 10;
echo("Intelligence is:" @ $intelligence);

--fields: object dependent storage for data that is directly associated with a particular instance of an object. This data is stored directly within the memory of the object itself (at least at the theory and use level), and is accessable once you have an objectID for that object.

Fields can be persistent, or dynamic. A Persistent Field means that the variable is actually created within the c++ class, and "exposed" to scripting so that the scripter can change it. The underlying code is going to use this value for various behaviors for the object (physics, rendering, movement, etc). Dynamic fields are created by the scripter simply by first using them, and cannot/will not be "recognized" by the underlying class implementation.

// we assume that we have a valid objectID of a valid Object stored in the global variable $Player
$Player.myField = 15;
echo( "MyField is:" @ $Player.myField );
#4
02/14/2007 (2:16 pm)
Ok, Thank you. The "echo("Intelligence is:" @ $intelligence);" was great in knowing if the calculations are going through on the consol window, and are correct...

And the stats have started working to personal expectations. (Now to add/join it to a GUI... )

Thank you both for the assistance.