2015-05-03 18:12:24 (edited by stefan_ilioaica 2015-05-03 18:14:08)

Hi, guys.
As the title of this topic says, I'd like to know how to make an inventory in BGT. All I know is  that it should be made likea menu.
But, my problem is adding the items in it. Let's say, for example, I buy a knife, a pizza and an ice-cream. How I can make these itmes to appear in my inventory? I've thought at a lot of things, but nothing comes to my mind to help me in this problem.
Can someone explain me a bit and give an example as well?
All that I'd like to know is how do you make these itmes, which could be a tousand different kins of items, to appear in your inventory when you buy, pick up or stal them for somewhere for example.
I hope I've explained it well... I'm not an expert in BGT, I can work with the menus, string and int variables, and I can combine them to make something... playable. But I really don't know how to use all those things together to make a nice inventory.

2015-05-03 18:19:41 (edited by Genroa 2015-05-03 18:22:37)

For things like inventories, I think that you should use classes and objects. An inventory is basically an array containing objects. In order to be able to do this (because arrays can only contain objects of the same type), all items are from classes inheriting from the same class, like Potion, Weapon and Armor, all inherit from Item. So, your perfect inventory would be a class containing an Item@ array and some functions to list it, add and remove items. smile

But other people may give you other solutions and they may be as good as the one I used for my project smile

2015-05-03 18:35:30

Hi,
I agree with genroa here. Have a class called item with a name property. Then have a function to create the inventory menu and loop through the array of items and put them lal in the menu.

2015-05-04 09:04:28

Actually theres a simpler way. You'd create an aray with strings. Now this wouldn't work if your items had special abilities all showed by an inventory, like 2 different sets of armor might have different things, and a class would be better for things in the end because you could drop them, and you could have a boolian spesifying weather it was in your inventory, but you could start with strings.
string[] inv;
inv.insert_last("knife");
inv.insert_last("armor");
inv.insert_last("icecream");
and as for the menu... this is asuming that you have dynamic_menu m;
string invmenu()
{
m.reset(true);
for(uint x=0; x<inv.length(); x++)
{
m.add_item_tts(inv[x], inv[x]);
}
int mres=m.run("Please select an item from your inventory", true);
if(mres==0) // escape
{
return "0";
}
else
{
return m.get_item_name(mres);
}
}
esentually, here could be some code you might use for when you select an item.
if(key_pressed(KEY_I))
{
use(invmenu());
}
void use(string item)
{
if(item=="0")
{
return; // they pressed escape.
}
if(item=="key")
{
if(position==doorposition)
{
// unlock code.
}
else
{
// message saying the key can't be used here.
}
}
}
Now note that this was written in a hurry and is far from perfect, but it's just an example of ways you could go about it. That code probably shouldn't be used in the end, but if your looking for a kind of example, there you go. I could have done it way better but that code I wrote, though could contain compolation errors, the logic of that code would somewhat work. Good luck.

I am a web designer, and a game developer. If you wish see me at http://www.samtupy.com

2015-05-04 10:08:04

But this isn't an items inventory, this just...a string array sad how can you really know what item are stored in? With their names? That's kind of weird sad

2015-05-04 20:06:35

that's why I said that code shouldn't be used, I just wanted to provide an example of the menu and posible ways to use the items. I wrote it at 2 this morning and even said it wasn't perfect.
That could easily be switched to a class, just change the string[] inv to like an array with all those items in there, which would be stored in a class.
item@[] inv(0);
and have like an add item function
void add_item(*values the item class requires*)
{
item i1(values);
inv.insert_last(i1);
}
That above code is asuming your item class can take all those values in a constructor. And the menu would look almost the same, but it might be a bit different. And remove item would have to probably loop.
void remove_item(string name)
{
for(uint x=0; x<inv.length(); x++)
{
if(inv[x].name==name)
{
inv.remove_at(i);
break;
}
}
}
Again, this was put together very quickly and doesn't contain a fully working inventory, just some of the logic and posibilities. That string thing I had before would have worked, but I even said it's not recommended. Anyway, theres more examples, but don't use that code, it's not good, only look at it and you might get the logic i'm using here.

I am a web designer, and a game developer. If you wish see me at http://www.samtupy.com