Inventory question
Hi all,
I'm making an adventure game and i'm trying to get my items to recognise when a slot is empty in the inventory. so when an item is used the others move down the order.
I have an ITEM COUNT rule that counts up with each item collected and counts down when they are used.
And I have a rule for each item that tells it- WHEN ITEM COUNT=1 GO TO SLOT 1, WHEN ITEM COUNT=2 GO TO SLOT 2 etc.
The problem I have is that all the items have the same rules and so they all go to the same slot. If I have 1 item it goes to slot1,
and if I have 2 items they both go to slot 2 etc.
I'm sure the answer is staring me in the face but i'm just getting more confused.
Any help appreciated.
I'm making an adventure game and i'm trying to get my items to recognise when a slot is empty in the inventory. so when an item is used the others move down the order.
I have an ITEM COUNT rule that counts up with each item collected and counts down when they are used.
And I have a rule for each item that tells it- WHEN ITEM COUNT=1 GO TO SLOT 1, WHEN ITEM COUNT=2 GO TO SLOT 2 etc.
The problem I have is that all the items have the same rules and so they all go to the same slot. If I have 1 item it goes to slot1,
and if I have 2 items they both go to slot 2 etc.
I'm sure the answer is staring me in the face but i'm just getting more confused.
Any help appreciated.
It’s not a bug – it’s an undocumented feature
Best Answers
-
KevinCross London, UKPosts: 1,894
How about having a Boolean attribute on the item to show whether or not it's already in a slot. If it is in a slot it ignores your slot/count rules.
The other way would be store them in a table which will reorder/shift up when you delete an item from the middle I.e. deleting item 4 will automatically put item 5 into slot 4 and item 6 into slot 5. Adding a new item with add row to end will also sort the counting slots used problem too -
KevinCross London, UKPosts: 1,894
Cool good luck!
You'd still have to do some logic to check the table for each item and draw them on the screen in the right slots but that shouldn't be too difficult, and I'm guessing you already have the positioning logic in place with your current approach.
Holla if you get stuck -
KevinCross London, UKPosts: 1,894
I got the shifting into empty slots thing working now. However there seems to be a bug when you empty all slots and start adding items in again the first two you add go into the first slot. I can't see what's causing this and why it doesn't happen the first time around.
I've added a new game attribute called Shift To Slot (couldn't think of a better name) which controls the filling of empty spaces.
I'm not going to be able to spend anymore time on it, but hopefully you'll be able to find the problem or at least get a better understanding on how you might set it up for your game.
The other alternative would be to look at adventure game templates which have an inventory bar to see how they've done it
Let me know if anything is unclear.
Answers
I figure option 2 is probably the way to go, I'll just have to get my brain functioning properly again in order to implement it!
It’s not a bug – it’s an undocumented feature
It’s not a bug – it’s an undocumented feature
No i'm still confused!
Do you think you could do a logic flow diagram to illustrate what rules would go where?
Thanks in advance
It’s not a bug – it’s an undocumented feature
When you click on an item from the top of the screen it will go into the first free inventory slot, and in the order you click the items. If you click the item when it's in the inventory slot it goes back to the top, to it's original x and y position.
I'm stuck at the moment at the next bit which is shift the items a long when there's a spare slot in between them, i.e. if you have 4 items in the first 4 slots and you take out item 2 you'd probably want item 3 to go into slot 2 and item 4 into slot 3.
Obviously in a real game you won't want to remove them from the slot just by clicking them but it'll be a similar behavior for items that have been used/discarded.
If I figure out the shifting slot thing I'll send a new version.
Yeah its the rules that shift them along that I am having the problem with.
Because they all have the same rule they tend to want to move to the same slot
Again thanks
It’s not a bug – it’s an undocumented feature
I think I can make it work now.
It’s not a bug – it’s an undocumented feature
I've uploaded the same file here: http://www.kevincross.co.uk/?attachment_id=125 incase the attachments on the post get deleted in the near future.
It’s not a bug – it’s an undocumented feature