Author Topic: getDatablock returning Nil  (Read 869 times)

So, I've created a nifty little dynamic brick placing function, yet for some odd reason all of my echos are returning nil except for "%type" which returns an ID, 1032 to be precise. Anyway, when I place the brick it recognizes it as the datablock but all of the other fields do not compute.

Note: LeftPrint is a function I made. Also, the brick is TreeBrickData, not brickTreedata.

Code: [Select]
$StrName["TreeBrickData"] = "TreeBrickData";
$StrMat["TreeBrickData"] = "Root";
$StrCost["TreeBrickData"] = 1;
$StrConfirm["TreeBrickData"] = "You planted a tree!";

package Lolplant
{
function fxDtsBrick::onPlant(%brick)
{
%client = getBrickGroupFromObject(%brick).client;
%brickdatablock = %brick.getDataBlock();
%type = %brick.getDataBlock();

if(%brickdatablock $= nameToID($StrName[%type]) && %client.quantity[$StrMat[%type]] >= $StrCost[%type])
{
echo(%type);
echo($StrConfirm[%type]);
echo($StrCost[%type]);
echo($StrMat[%type]);

%client.Leftprint("\c1" @ $StrConfirm[%type] @ "");
%client.quantity[$StrMat[%type]] -= $StrCost[%type];
%client.quantity["Weight"] -= $StrCost[%type];
parent::onPlant(%brick);
return;
}
}
};
activatepackage(Lolplant);

For one, I think it's fxDtsBrick::onPlant(%data,%brick) not just %brick.

For one, I think it's fxDtsBrick::onPlant(%data,%brick) not just %brick.
Anyway, when I place the brick it recognizes it as the datablock as an ID but all of the other fields do not compute.

Code: [Select]
%data = TreeBrickData.getID();
$StrName[%data] = "TreeBrickData";
$StrMat[%data] = "Root";
$StrCost[%data] = 1;
$StrConfirm[%data] = "You planted a tree!";

You have defined $StrNameTreeBrickData as a variable by the array. Your echoes are looking for $StrName1032.

Code: [Select]
%data = TreeBrickData.getID();
$StrName[%data] = "TreeBrickData";
$StrMat[%data] = "Root";
$StrCost[%data] = 1;
$StrConfirm[%data] = "You planted a tree!";

You have defined $StrNameTreeBrickData as a variable by the array. Your echoes are looking for $StrName1032.
How would I revert the ID back to a name? Could I just remove nametoID? When I remove it though, it doesn't seem to work.

You could do %brick.getDatablock().getName()

Code: [Select]
if($StrName[%type] && %client.quantity[$StrMat[%type]] >= $StrCost[%type])That checks if there is a $StrName relating to the brick's type, which appears to be what you're checking. You could also remove %brickdatablock = %brick.getDataBlock(); since you've already done the same thing with %type.

Thanks, I fixed it.
« Last Edit: July 10, 2009, 11:50:49 AM by Gorella »