About Store Forum Documentation Contact
Donations:
243$/mo



Post Reply 
inventory help
Author Message
craksy Offline
Member

Post: #1
inventory help
ok, i am making a inventory sytem, and i ran into a problem:
when my character pick up an item, how would it detect which type of item it is, so it can find the right icon to put in the inventory window?

and heres my plan for the inventory:
name all the slots "slot1", "slot2", "slot3", and so on.
make a currentSlot variable
and when the item is picked up, just put the item icon, in the inventory, something like:
"slot"+currentSlot.set(Gfxs(items, icon));
currentSlot++;

the reason i am saying this, is that there may be a better way to do this, or some build in feature in the engine that could make it easier or something?

anyway, hope you can help grin
01-06-2009 03:18 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: inventory help
create an extended class of Game::Item for all in-game items (for example "Item : Game::Item")
then add "Gfx *icon" parameter; into it

then when creating a visible representation of items use a simple Region with List
in the you can use ListGroup to use "parameter" as DATA_GFXP (data type : pointer to Gfx)
creating Lists is done in one of the tutorials in Gui folder
as a base data for the list (List.setData) you can use player itemContainer (which is a Memx, supported by the list)
01-06-2009 10:30 AM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #3
Re: inventory help
i am not i understanded it all...
i understand the part where i make a extention of the Item struct, and give til at icon parameter...
but how exactly am i going to set the icon, for each item? add a variable to the object, in the world editor or... ?

could you just post a quick example code, to give me an idea of how it should be done?

thanks grin
01-06-2009 01:49 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
Re: inventory help
you can make it 2 ways (at least) :

1) in world editor store for each item additional parameter like
String icon_name, and inside it set the path to your icon, for exameple String icon_name "obj/item/axe/icon.gfx"
later in game when creating item object (Item::create)
icon=Gfxs(obj_params.getParam("icon_name)->asStr());

or simplier

2) keep all icons of your meshes named as mesh_name+".gfx" (having a mesh "obj/item/axe/axe.mesh" have icon "obj/item/axe/axe.mesh.gfx")
then when creating item object (Item::create)
Char *mesh_name=Meshs(obj_params.mesh);
icon=Gfxs(S+mesh_name+".gfx"); // use mesh name appended by ".gfx"
01-06-2009 02:48 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #5
Re: inventory help
thanks alot!
ill remember it for later, because i want the basic inventory to work before i add the inventory window itself!
and that leads me to a new question:
using the pickUpItem(Items[0]); will take the first item available in the items array...
what if i want to take any item, as long as its within a given range of the character?
could i just make a function containing a "for loop", going through the whole array, and make it return the item, and put the function as a parameter?
like:
Code:
Game::Item checkItemsFunction()
{
Item availableItem;
for(i=0;i<items.length;i++)
  {
     if(Dist(Items[i].pos(), Players[0].pos())<1.5)
     {
          availableItem = Items[i];
     }
  }
  return availableItem;
}
??
or are there an easier way to do this?
thanks grin

btw. i just wrote the text here in the forum, so i dont know if i misspelled anything :/
also i have never worked much with arrays, so theres proberly something wrong about my code -.-'

anyway: hope you can help me
01-07-2009 04:26 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
Re: inventory help
you can use this code, or use the built-in functions World.objQuery
which will return pointers to objects which are positioned in a certaing region (like a box or a ball)
you can specify for them the region, and optionally object type (so OBJ_ITEM in your case)
01-07-2009 04:29 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #7
Re: inventory help
if it would work with my code i would prefer to use that...
i want to do stuff by my self as far as i can, and its so rarely i figure out the stuff by my self, so i prefer to use my own solution smile
after all i cant have you make my code forever pfft

but thanks for your confirmation about my code, and your suggestion grin
01-07-2009 04:37 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #8
Re: inventory help
just another quick question:
how do you get the size of an array? :oops:
i forgot that "array.length" is actionscript, and not C++..
i only see stuff like elmsize, and absElms and stuff... i am not completely sure what absolute elements is, but would i be able to use it for the code i posted before?
01-07-2009 04:44 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
Re: inventory help
you can use

for(Int i=0; i<container.elms(); i++)

or
REPA(container)

for info about absolute indexes check documentation\programming\memory containers
01-07-2009 05:12 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #10
Re: inventory help
i figured out that sizeof(array) didnt give me any errors, but would it cause trouble with Esenthel engine?
else i think ill use REPA...

anyway, i got some errors! heres my code:

Code:
Game::Item checkItems()
{
    Game::Item availableItem;
    for(int i=0;i<sizeof(Items);i++)
    {
        if(Dist(Items[i].pos(), Players[0].pos())< 2.0)
        {
            availableItem = Items[i];
        }
    }
    return availableItem;

}

and got the following errors:

1>.\Game.cpp(37) : error C2783: 'void Esenthel::Game::Item::operator =(Esenthel::Game::Item &)' : could not deduce template argument for 'TYPE'
1> c:\programmer\microsoft visual studio 9.0\vc\include\esenthelengine\Game/Item.h(47) : see declaration of 'Esenthel::Game::Item::operator ='
1>.\Game.cpp(40) : error C2558: struct 'Esenthel::Game::Item' : no copy constructor available or copy constructor is declared 'explicit'


thanks in advance xD
01-07-2009 05:18 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #11
Re: inventory help
sizeof(array) returns the number of bytes which the container has (not the number of elements)

you can't exactly copy an item
like this
"availableItem = Items[i];"
you need to remember a pointer to the item
Item *temp=NULL;

temp=&Items[i];

or the index

Int temp=-1;
temp=i;
01-07-2009 05:47 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #12
Re: inventory help
thanks, but that one gave me even more errors :S

heres my code now:
Code:
Game::Item checkItems()
{
    Game::Item *temp=NULL;
    for(int i=0;i<REPA(Items);i++)
    {
        if(Dist(Items[i].pos(), Players[0].pos())< 2.0)
        {
            temp = &Items[i];
        }
    }
    return *temp;

}

and get the following errors:
1>.\Game.cpp(33) : error C2059: syntax error : 'for'
1>.\Game.cpp(33) : error C2143: syntax error : missing ')' before ';'
1>.\Game.cpp(33) : warning C4552: '>=' : operator has no effect; expected operator with side-effect
1>.\Game.cpp(33) : error C2143: syntax error : missing ';' before ')'
1>.\Game.cpp(33) : error C2059: syntax error : ')'
1>.\Game.cpp(34) : error C2143: syntax error : missing ';' before '{'
1>.\Game.cpp(40) : error C2558: struct 'Esenthel::Game::Item' : no copy constructor available or copy constructor is declared 'explicit'


normally just fixing one of the errors will solve, the alle the syntax errors, so i guess it looks worse than it is...
its just: which error is causing the rest? :/

thanks in advance xD
01-07-2009 06:14 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #13
Re: inventory help
REPA(container) is a macro for something like for(Int i=0; i<container.elms(); i++) not for number of elements
for number of elements you've got another macro ELMS(container)
so you need to just type

Code:
Game::Item *temp=NULL;
   REPA(Items)
   {

also don't return the object, but retutn the pointer to an item
01-07-2009 06:23 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #14
Re: inventory help
Quote:also don't return the object, but retutn the pointer to an item
eeh.. what exactly do you mean?
i thaught that *Items was a pointer? :oops:
but as said in another post: i have never understanded the smart about pointers, so i have just read the theory through, and forgot the most of it, since i never use it in general programming :/
01-07-2009 08:04 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #15
Re: inventory help
when you define a pointer you do
Item *item;
with that definition:
- 'item' is a pointer
- '*item' is an object

so returning a pointer:

Code:
Item* Function()
{
  Item *item;
return item;
}
01-08-2009 01:08 PM
Find all posts by this user Quote this message in a reply
Post Reply