How do I move data from one index in an array to another?

0 favourites
  • 14 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hi,

    I made an inventory for my game and I just tried to make it possible to move objects from one slot in an array to another by clicking on the slots. I tried to let the game put the coordinates of the first click on a slot in a global variable and then do the same with the second one. After the two clicks are done, the game sets two booleans to true (first one set = true, second one set = true). Then when these are true the game sets the value on the index of the second click to the value from the index of the the first click and then deletes the values from the first click. The array is 3 dimensional and one the X axis it stores the item ID, on the Y axis it stores the item count and on the Z axis it can store even more items (every index on the Z axis is the storage of another inventory or chest).

    I can't find a way to get this working and also I think that there could be an easier way. Does anyone have an idea of doing that?

    Thanks!

  • Anyone?

  • korbaach

    ahh that's a nice file. I feel like I already know more about arrays. +1

  • Thank you korbaach,

    I'll try that right now!

    Thanks again

  • korbaach,

    Does your method also work with 3 dimensional arrays? Because as I said I want to be able to move an object from for example 2,0,0 (From inventory because Z is 0) to 5,0,1 (From the first chest because Z is 1). But I think the Array.IndexOf expression doesn't work with 3 dimensional arrays.

    Thanks!

  • aquadijoib you can always find IndexOf "#"

    ArraySwap3D.capx

  • korbaach,

    Thank you so much for all your examples. But I don't know how to move an item from one chest to another or from the inventory to a chest.

    Thanks again!!!

  • korbaach,

    Can you help me one more time please?

    I'm still not able to make it possible to move from chest to chest or from chest to inventory. I mean from one Z index (Storage) to another.

    Thanks again!

  • I'm still not able to make it possible to move from chest to chest or from chest to inventory. I mean from one Z index (Storage) to another.

    you probably need to save Z-index of first item...

    something like:.......................................................................... ArraySwap3D2.capx

  • korbaach,

    Thank you again for your amazing example! <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    I implemented the system from your example in my project and tried it out. Something happens, but not exactly what I want <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink"> .

    The only thing that was changed is that I have 2 different types of slot objects. One for the inventory and one for the chest. Because I wanted the inventory slots to be next to the chest slots. So I thought that I simply have to duplicate it for the chest and the inventory.

    I put some screenshots of my events below. If that's not enough, please tell me and I'll send you my capx.

    Thanks!

    Links (in correct order):

    https://drive.google.com/open?id=0B7r2W ... HNWVF93QVU

    https://drive.google.com/open?id=0B7r2W ... DJGVTNDTW8

    https://drive.google.com/open?id=0B7r2W ... U1tc3Yxams

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ... please tell me and I'll send you my capx.

    please...

  • korbaach,

    I sent you the capx of my whole project as a PM. The game is in space so you have to go to the planet next to the start and the ship will automatically land there . Then you leave the ship with F. There is a piece of wood on the planet and everytime you go over it, it adds 1 more wood to the inventory. With Tab you can open the Inventory and when pressing E and standing in front of the chest (the blocky thing on the planet) you can open it. The swap works for the first time I think. But when you try to swap it again, only the amount shows up and everything messes up. In the array it shows NaN (Not a Number?).

    Sorry if my project is a little messy.

    Thanks!

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