Rearranging table in game

fmakawafmakawa Member Posts: 559

Hi folks,
I have a sort of inventory and I would like to rearrange it (I'm using a table). I have an up and down button. How do I make any of button move the contents up or down the table. My current method creates a new row or deletes instead of rearranging. I'm sure its right in my face and simple and I'm being dunce. Any one? Thanks folks.


  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,928

    I prefer to shift the viewable data rather than shift the actual data structure. An example would be that if you have four inventory slots, each one has a self.num integer set to 1, 2, 3, or 4. That corresponds initially with a table row. But if you add a fifth row to the table and only want to display four items at a time, you then might show 1, 2, 3, and 4; or you might add one to self.num and display 2, 3, 4, and 5. So the table functions for that actor use self.num+self.offset where self.offset is the number of rows below the start of the table. This is similar to how I setup inventory pages where you can scroll through pages of items (e.g. 1, 2, 3, 4 then 5, 6, 7, 8, then 9, 10, 11, 12... each time the user taps the 'next page' button, I just add four to self.offset).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • fmakawafmakawa Member Posts: 559

    @tatiang ah! But all the slots are viewable. Its their placement that needs to change. ie what was in slot 4 is now in slot 3 or 2 etc.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,928
    edited April 2016

    Right, but you shouldn't need to do ANYTHING with the table. You should just change the offset value. I guess I might need more info from you but let's say you have 20 slot actors and 20 table rows and you need everything to bump up one row. You'd change the offset value by (negative) one and then need a way to make sure you aren't referencing row #0 of the table. Something like this:

    If self.num=0 then change attribute self.num to 20.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,862

    Here is demo that shows the principle:

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,914

    See my videos on making an inventory system.

  • fmakawafmakawa Member Posts: 559

    @RThurman thanks for the demo. Its great and I'll actually use it for something else but I think I wasn't clear for both you and @tatiang. Lets say I have an object at slot 2 and that is a position in the table and I want to move it slot 7. Slots 3-7 would then move up to allow the transition. The transition can be one by one or drag and drop. @Lost_Oasis_Games I'm going through your videos again now. I keep getting muddled some how.

Sign In or Register to comment.