About Store Forum Documentation Contact



Post Reply 
Inventory Memx Container
Author Message
AndrewBGS Offline
Member

Post: #16
RE: Inventory Memx Container
Yup, well that's pretty much what I'm doing. But the fact that nowhere in my accessible code was the part where an item from world is added to my inventory messes up my plan.
And this is what I keep asking and I can't get a straight answer to.
Where's the code that adds world items to my inventory? How can I change it?
04-24-2013 02:24 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #17
RE: Inventory Memx Container
Wouldn't that just be Items.add( item ); ?
04-24-2013 06:06 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #18
RE: Inventory Memx Container
I suppose it would, if only there was one.
I've studied the inventory tutorial for hours and there was no place where the item was added in that memx container. I suppose some super update function does that, but i have no idea which. Thus, I have no idea how to alter it and make it do what i want of it.
04-24-2013 06:09 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #19
RE: Inventory Memx Container
The tutorial uses this line:
itemPickUp(*item); // pick it up

It's not exposed(it's in Game.Obj, which isn't included with the game objects source, unfortunately), so we don't know what is going on inside the function.
04-24-2013 06:32 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #20
RE: Inventory Memx Container
:-< /sigh
That's what I figured out.... so there's no way for me to change what happens between that and the point where the item is in my memx container? It kinda sucks....
04-24-2013 06:33 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #21
RE: Inventory Memx Container
(04-24-2013 07:18 AM)andreim44 Wrote:  I'm trying to implement STACKS, so when an item that is already in the memx is added, i don't want a new instance of that item in there, I just want a corresponding index counter to be incremented.
Can you tell me how and where to do that?
If you already have such item, then increase its counter, and instead of pickup method, remove the object from the world (delete it).
Otherwise you can call pick up method.
04-25-2013 01:03 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #22
RE: Inventory Memx Container
Oh yeah. Suddenly I feel silly for not thinking of this.
Thanks, that should fix it smile
Now to have the memx NO_COPY_CONSTRUCTOR fixed and I can have my long desired inventory smile
Thank you.
04-25-2013 01:38 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #23
RE: Inventory Memx Container
Hello,

Memx does not have NO_COPY_CONSTRUCTOR.
04-25-2013 02:03 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #24
RE: Inventory Memx Container
Huh. Funny, I found this mentioned in another thread.
Then why when I do this:

Item x=inv.items[i]; //inv is the inventory class in the tutorials

Whenever I try to use anything related to that x item I get this error:
error c2783: 'void EE::Game::Obj::operator = (const EE::Game::Obj &)' : could not deduce template argument for 'UNUSED'

? I want to get an Item object, not reference, from that container. How should I do that if not this way?
04-25-2013 02:45 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #25
RE: Inventory Memx Container
Back to the "If you already have such item, then increase its counter, and instead of pickup method, remove the object from the world (delete it)." idea, how do I achieve that? Apparently Memx's search functions all work on address, and every single item in the world seems to be new to the container.

I have 3 apples on a table, my code:
if(!inv.items.contains(item))
itemPickUp(*item); // pick it up

doesn't stop the player from getting 3 distinct items instead of one. How can I use memx to check if the actual ITEM is already in there?
04-25-2013 05:52 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #26
RE: Inventory Memx Container
In that example, item should be pointing to the specific memory location of the one that is selected on your table. It is a very specific apple. contains() will only check to see if you have that specific apple, not any apple.
Check first to see if you have any items of the same type-maybe type APPLE. Doesn't matter, because you can check Items[x].type( ) == item.type( ); to test if they are the same type of item.
04-25-2013 07:28 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #27
RE: Inventory Memx Container
So... I should have a field that should define my item, just have the same object dragged & dropped in the world won't get me the same object :(.
So let's say I give every single object a distinctive parameter. To check the Memx for containing that specific parameter do I have any function, or do I have to iterate through the Memx and check all items myself?
04-25-2013 08:16 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #28
RE: Inventory Memx Container
Item has a type field already.
You are getting down to basic C++ here. Try checking out some examples of how simpler games use inventory systems-even text based games might offer some insight.
04-26-2013 12:25 AM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #29
RE: Inventory Memx Container
Type field is an enum, I don't think using an enumeration to distinguish apple, plum, banana, orange and so on is a good idea. But nevermind that, I'm just asking if there is a smooth way of searching memx by type, or do I have to do it myself, like this:

for(int i=0;i<items.absElms();i++)
if(items[i].name=<value>) return 1;
return 0;

//this would be a manual search. I'm pretty much obsessed by efficiency, so there's a better to search for an item by value not by address in that container I'd be happy to find out.
04-26-2013 06:17 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #30
RE: Inventory Memx Container
Hello,

I've redesigned game object item methods,
next release will have these changes:
Quote:-IMPORTANT: Game::Obj::item* methods were replaced with Game::World.move*ObjTo* methods (which allows much better flexibility of moving objects between the world and custom containers, for example previously characters were allowed to store only one class of item objects returned by 'itemContainer', now there's no such limit)
-IMPORTANT: because Game::Obj::itemContainer was removed and since in the past it was used to automatically save item objects in Game::Obj::save/load, now you need to manually save object item containers (if any) in your custom game object class

following methods will be available in Game::WorldManager
Code:
Obj* moveWorldObjToStorage  (Obj &  world_obj, Memx<Obj> &    storage                            ); // move '  world_obj' world   object into a custom 'storage' object container, this function will be performed only if '  world_obj' belongs to this world    and 'storage' is a container                   storing exactly the same type as the '  world_obj', if those conditions are met then the object will have its 'willBeMovedFromWorldToStorage' method called, then it will be removed from        world  and placed in the storage   , then it will have its 'memoryAddressChanged' method called followed by 'wasMovedFromWorldToStorage' and address of the object (now inside the     storage container) will be returned, if this method fails then NULL  is returned and no operation is performed
         Bool  moveStorageObjToWorld  (Obj &storage_obj, Memx<Obj> &    storage, C Matrix  *obj_matrix=NULL); // move 'storage_obj' storage object into world                              , this function will be performed only if 'storage_obj' belongs to '    storage' and  world    is capable (see 'setObjType') of storing exactly the same type as the 'storage_obj', if those conditions are met then the object will have its 'willBeMovedFromStorageToWorld' method called, then it will be removed from      storage  and placed in the world     , then it will have its 'memoryAddressChanged' method called followed by 'wasMovedFromStorageToWorld' and true                                                         will be returned, if this method fails then false is returned and no operation is performed, 'obj_matrix'=optional parameter specifying new object matrix applied to the object when being moved to world (it's not applied if it's NULL or this method returned false)
   static Obj* MoveStorageObjToStorage(Obj &storage_obj, Memx<Obj> &src_storage, Memx<Obj> &dest_storage   ); // move 'storage_obj' storage object from 'src_storage' into 'dest_storage'  , this function will be performed only if 'storage_obj' belongs to 'src_storage' and 'storage' is a container                   storing exactly the same type as the 'storage_obj', if those conditions are met then the object                                                                      will be removed from 'src_storage' and placed in 'dest_storage', then it will have its 'memoryAddressChanged' method called                                          and address of the object (now inside the new storage container) will be returned, if this method fails then NULL  is returned and no operation is performed
05-05-2013 02:40 PM
Find all posts by this user Quote this message in a reply
Post Reply