Game Development Community

SimGroup.add(SimObject) not quite right

by Robin Rudick · in Torque Game Engine · 09/28/2006 (9:22 pm) · 1 replies

Im trying to add a simobject to a simgroup so i can call it all as one string, here is my code so far

function serverCmdCreateInventory(%client, %UserID)
{
%Name = "Inventory:" @ %UserID;
echo("InID: ", %Name);
%Inventory[%UserID] = new SimGroup(%Name);

%Inventory[%UserID].Owner = %UserID;


%InDB = new MySQL();
%InDB.host = "127.0.0.1";
%InDB.port = "3305";
%InDB.user = "root";
%InDB.pwd = "";
%InDB.flag_compress = false;
%InDB.flag_ssl = false;
%InDB.db = "Torque";
%InDB.ValidateSettings();
%InDB.Connect();
%InDB.Query ("SELECT * FROM player_items WHERE UserID = \'" @ %UserID @ "\'");
%result = %InDB.StoreResult();
%amount = %InDB.NumRows(%result);

// %group = new SimGroup(Test); %object = new SimObject(); %group.add(%object);

for (%i= 0; %i< %InDB.NumRows (%result); %i++)
{
%InDB.FetchRow (%result);
%ItemObjName = "Item:" @ %i;
%ItemObject[%i] = new SimObject(%ItemObjName);

%ItemObject[%i].ItemID = %InDB.GetRowCell (%result, "ItemID");
%ItemObject[%i].ItemAmount = %InDB.GetRowCell (%result, "Amount");

%Inventory[%UserID].add(%ItemObject[%i]);

echo("ItemID: ", %ItemObject[%i].ItemID);
echo("ItemAmount: ", %ItemObject[%i].ItemAmount);

%Inventory[%UserID].add(%ItemObject[%i]);

echo("ItemID: ", %Inventory[%UserID].ItemObject[%i].ItemID);
echo("ItemAmount: ", %Inventory[%UserID].ItemObject[%i].ItemAmount);
}

echo("After ItemID: ", %Inventory[%UserID].ItemObject[1].ItemID);
echo("After ItemAmount: ", %Inventory[%UserID].ItemObject[1].ItemAmount);

%InDB.FreeResult (%result);
%InDB.Close();
%InDB.Delete();
}

for some reason, %Inventory[%UserID].ItemObject[%i].ItemID doesnt return the value that should be stored at it, however, %ItemObject[%i].ItemID continues to return the value that was stored at it. however if i do the listobject command it says there inside of the simgroup, as well in the world editor it says there stored there. not sure whats going on, some more insight would be most helpful, thanks!

#1
09/29/2006 (8:41 am)
Hey there,

You are making one simple problem. As far as I know, you cannot access the members of a SimGroup by name, only by index.

You are doing
SimGroup[groupIndex].itemName[itemIndex].attribute;

What you need to do is
SimGroup[groupIndex].getObject[itemIndex].attribute;
and it should work beautifully.

Enjoy,
Shawn