Game Development Community

something I don't understand (torque script help)

by TrapHouseGaming · in Torque 3D Beginner · 11/10/2017 (11:04 pm) · 6 replies

basically my question is this,
why is it that in a function I can find an object using a raycast:
%obj = getWord(%raycast,0);

then i can then find the object's datablock and variables stored on its datablock with:
%obj.dataBlock or %obj.datablock.height ect.

and that all works just fine, except as soon as I bring %obj into the next function:
SpawnShit(%obj);

thats when I can no longer access variables associated with %obj.datablock:
function SpawnShit(%obj)
{
%thisWontWork = %obj.datablock;
%bigTimeSyntaxError = %obj.datablock.height;

%butThisStillWorks = %obj.wetness;
}

ive been working around this for a long time in torque and I just don't understand why this is. and if this isn't a real problem and its a mistake on my end, i can post the actual scripts i'm struggling with.

About the author

long time torque player, decent at scripting and modeling, no good at textures, I primarily work with milkshape and blender. Follow progress on my shitty lil game: https://discord.gg/qsXb9CG


#1
11/11/2017 (10:24 am)
I haven't seen %obj.datablock used anywhere.

The correct way to do: %dataBlock = %obj.getDataBlock();
%height = %dataBlock.height;
#2
11/11/2017 (10:25 am)
Also make sure the object exists with: if(isObject(%obj)){...}
#3
11/12/2017 (10:07 pm)
Wow thanks man, I'm surprised I've never realized the use of that function before, self taught problems I guess. now to remove all instances of %obj.datablock from a thousand lines of code :)
#4
11/13/2017 (1:18 am)
one more question. is there any way to return a datablock's text name instead of its numerical id? I'm using it for this %newObjDatablock = %datablock.type @ %datablock.height @ %col.getdatablock(); where %col.getdatablock() is returning numbers as it should, but i need the text name of the datablock for the script. also i need a way to check if the %newObjDatablock is an existing datablock loaded into my level.
#5
11/13/2017 (2:11 am)
nvm, got it.
%col.getdatablock().getname()
found it here:
http://docs.garagegames.com/torque-3d/reference/classSimObject.html#a3f232a5965525540267871d9d6323e70
#6
11/13/2017 (7:34 am)
Someone read the docs! =)

Glad you got the answers you needed TrapHouseGaming.