Inventory, Items, I'm lost
by Hunter-Digital · in Torque Game Engine · 06/09/2008 (9:54 am) · 8 replies
I'm new at this type of scripting, I don't really understand all things :(
I'm currently stuggling to make an basic inventory system, just to add and remove items... but I can't seem to make anything more than this:
items.cs:
inventory.cs:
PS: I'm using the tutorial base package, the starter.fps is a bit too complicated.... I'd rather make the scripts from scrap.. also the game I'm making is singleplayer only :)
I'm currently stuggling to make an basic inventory system, just to add and remove items... but I can't seem to make anything more than this:
items.cs:
function ItemData::create(%data)
{
%obj = new Item()
{
dataBlock = %data;
static = false;
rotate = false;
};
return %obj;
}
datablock ItemData(Sword)
{
category = "Weapons";
className = "Weapons";
shapeFile = "~/data/weapons/sword_06.dts";
isInvincible = true;
mass = 1.0;
elasticity = 0.1;
friction = 1.0;
};
function Sword::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
%obj.delete();
/* What now ?! */
}
}inventory.cs:
function ShapeBase::invAdd(%this, %data, %amount = 1)
{
%this.inv[%data.getName()] += %amount;
}
function ShapeBase::invRemove(%this, %data, %amount = 1)
{
%this.inv[%data.getName()] -= %amount;
}
function ShapeBase::invGet(%this, %data)
{
return %this.inv[%data.getName()];
}PS: I'm using the tutorial base package, the starter.fps is a bit too complicated.... I'd rather make the scripts from scrap.. also the game I'm making is singleplayer only :)
About the author
#2
06/09/2008 (10:47 am)
Well, apart from the selection and clicking to pickup something ( with a target, not mouse ) that's too complicated for now, I'm trying to to pickup the object with the collision mode but I dunno what to do next in the /* What now ?! */ part :( ... the codes are inspired from starter.fps's scripts :)
#3
06/09/2008 (12:54 pm)
The engine provides an onCollision callback, scoped to the PlayerData datablock (I believe). That is the place where you could check and see if you collided with an object that you can pick-up (%collidedWith.getClassName() $= "Item") then go ahead and add to your inventory. The starter.fps pack already has code doing this, so you can look there for an example.
#4
06/09/2008 (2:54 pm)
Isn't there already an inventory system? All you have to do to use that is putmaxInv[[i]Sword[/i]] = 1;in the player datablock.
#5
06/09/2008 (3:23 pm)
That inventory system exists in the starter.fps kit. Hunter here is rolling is own, and learning how it works in the process.
#6
Also the inventory system from starter.fps is kind of complicated, I only need to add, get and remove items, I won't add a "drop" function or a maxinventory so I won't need them :)
After %obj.delete(); I don't understand how to add the item to the inventory... %obj and %this from the function kinda lost me :) ... the %this and %data from the (my) inventory system also lost me :(
06/10/2008 (3:54 am)
Exacly ! Anyway, I already knew what the onCollision did, thanks to the GettingStarted.pdf :) but I don't know some basics... like the :: thing in functions and variables, a . in variables or functions...Also the inventory system from starter.fps is kind of complicated, I only need to add, get and remove items, I won't add a "drop" function or a maxinventory so I won't need them :)
After %obj.delete(); I don't understand how to add the item to the inventory... %obj and %this from the function kinda lost me :) ... the %this and %data from the (my) inventory system also lost me :(
#7
"I'd like you to teach me to drive a car."
"Sure thing! Just walk over to the car here."
"Woah woah, what does walk mean?"
06/10/2008 (1:12 pm)
Ooo, so we need to back the truck up to syntax? Ok, tell you what. Why don't you start here and here, then come back and see if you have further questions. I'm not trying to "brush you off" or be patronizing, but in order to help you a common level of understanding needs to be established. Otherwise we have a situation where seriously limiting knowledge gaps occur."I'd like you to teach me to drive a car."
"Sure thing! Just walk over to the car here."
"Woah woah, what does walk mean?"
#8
@Hunter-Digital,
I had the same confusion. %this and %obj are just generic variables. They could have been named %variable1 and %variable2 or even %hunter and %digital.
Tony
iAmNotAprogrammer:)
07/01/2008 (2:58 pm)
@Mark - thanks for the links!@Hunter-Digital,
I had the same confusion. %this and %obj are just generic variables. They could have been named %variable1 and %variable2 or even %hunter and %digital.
Tony
iAmNotAprogrammer:)
Torque 3D Owner Mark Dynna