Problem with a "dynamic inventory swap" (project file included)

0 favourites
  • 5 posts
From the Asset Store
Full game Construct 2 capx code source to post on Google Play
  • Hello construct community,

    maybe someon can help me out with my problem ...

    I want to do a very simple inventory for a mobile game, and here are the specs:

    - The inventory has max. 3 slots

    - One slot is always visible (the active slot), 2 other slots are off screen

    - If the Player do a "Double-Tap" on the active slot, the other 2 slots pop in

    - Now the player can see the full inventory and can select a new item to set it active

    - If the player tap on a new item, the inventory should do a swap

    - The new selected item should appear on the very bottom slot (the new item is now active)

    - After the swap is done, the inventory should collapse (so only the new selected item is visible)

    - If the player do a "Double-Tap" again, the other 2 slots pop in again

    I'am not a programmer at all, but thanks to the simplicity of Construct 3, I managed to get something like this: https://drive.google.com/open?id=1E5GNxxhJ7VycAsnsDXR8UDQ2XuPPL54W

    The problem now is to collapse the inventory and only show the new active item (like in the beginning). I can't grab the 2 instances of the slots which should go off screen again, so the "Double-Tap" listener is active again.

    Plus I have no idea how to activate / connect the little "item counter" in the circle next to the inventory. The counter shoud count the amount of the active item (the items in the very bottom slot).

    Can someone watch the project file and give me some hints for the problems?

    I think the problems are not difficult, but for a non programmer like me ...

    Thanks for the time, have a nice day

    Andy

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The problem here is that it's not really a very simple inventory system and you've gone about it in a very visual way which means there are tons of global variables and redundant code. If you are making something like this it would be best to use an array then it can be done in several events, looking at your events it's just too difficult to work out what's going on, also if you plan to expand this in future it is going to be a bit of a nightmare. I would start again with an array where your inventory slots are 0,0 1,0 and 2,0. You can then put the amounts of those items and add to them at 0,1 1,1 and 2,1 which would solve your problem. Then when you are swapping items they move between 0,0 1,0 and 2,0 slot where 0,0 is always the 'active' item. That in itself would also be somewhat difficult for a beginner and if you are new to arrays but hey that's inventories :)

  • <p>Hey plinkie,

    thanks for your answer.</p>

    <p>Yes the code is very redundant because I have no practise in loops, functions and arrays. I can create an array and probably fill it with the items. But parsing and checking the array is way beyound my knowledge ...</p>

    <p>So the visual approach is almost there. The only thing that's not working is the collapse at the end, if an item was selected. I think in the last section of the code is something wrong.</p>

    <p>Thanks for your reply. I should do some tutorials related to arrays =)</p>

  • For the collapse I don't think any code is wrong, it's just missing. When you open it and set the slots to x+200 you need to have the ones that are not active move x-200 on a close. That's about it, so double tap on inventory when inventory open =1, set inventory open = 0 and move the inactive slots -200.

  • Ah ok, now it works fine.

    I had the collapse code in there, but didn't save it because there was an error. Now I placed the collapse code in a group and toggle the group active/inactive.

    Some conditions for the "Touch" has been executed in parallel with other "Touch" ... So the Group now acts like a function, I think ...

    If someone is interested, here it is (the coding is a horror, but it works):

    https://drive.google.com/open?id=1OC6anh-g-Dl3u1RfxO6WJXqhdouDbTlm

    I really should watch some advanced tutorials for functions and loops. THX plinki =)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)