Reading a field in a datablock from script
by Lawrence Brown · in Technical Issues · 07/16/2007 (4:25 pm) · 2 replies
I'm trying to write a function that checks a field assigned to an Item and then acts accordingly. Here's the datablock for the Item (Edited to the relevant sections):
datablock ItemData(RedFlag)
{
category = "Flags";
// Basic Item properties
...
FlagColor = 1;
};
And here's the function:
function Flag::onPickup(%this, %obj, %shape)
{
if (%obj .FlagColor == 1)
{
...insert code here...;
}
}
The function works. The "Flag" actually gets picked up and so on.
My problem is that "%obj.FlagColor" never returns a value. It's just blank. If I do an echo of RedFlag.FlagColor, it returns 1. If I do an echo of %obj.FlagColor, it just stays blank.
Any ideas on what I'm doing wrong or how I can get this to work? I've searched the forums without much luck, and all the docs and books make it seem like all you have to do is add the line with your custom field to the datablock and then it's accessible via "%DataBlockName.YourField", but no matter what I do, echo(%obj .FlagColor) always has an empty return.
Thanks for any help. Probably something basic I'm missing.
datablock ItemData(RedFlag)
{
category = "Flags";
// Basic Item properties
...
FlagColor = 1;
};
And here's the function:
function Flag::onPickup(%this, %obj, %shape)
{
if (%obj .FlagColor == 1)
{
...insert code here...;
}
}
The function works. The "Flag" actually gets picked up and so on.
My problem is that "%obj.FlagColor" never returns a value. It's just blank. If I do an echo of RedFlag.FlagColor, it returns 1. If I do an echo of %obj.FlagColor, it just stays blank.
Any ideas on what I'm doing wrong or how I can get this to work? I've searched the forums without much luck, and all the docs and books make it seem like all you have to do is add the line with your custom field to the datablock and then it's accessible via "%DataBlockName.YourField", but no matter what I do, echo(%obj .FlagColor) always has an empty return.
Thanks for any help. Probably something basic I'm missing.
#2
Worked beautifully.
Many thanks.
07/16/2007 (5:02 pm)
Aha! So simple and logical once you know the secret:)Worked beautifully.
Many thanks.
Torque Owner Andy Rollins
ZDay Game
function Flag::onPickup(%this, %obj, %shape) { if ([b]%obj.getDatablock().FlagColor[/b] == 1) { ...insert code here...; } }