Advice on Chest/Container system

Discussion in 'Programming' started by FacesOfMu, Feb 10, 2019.

  1. FacesOfMu

    FacesOfMu Member

    Joined:
    Jun 23, 2018
    Posts:
    44
    Hi there,
    I'm working on a sandbox game and trying to figure out some simple ways of handling chest/container type objects that store a bunch of other item objects persistently. I'd like some ideas on how people go about this.

    Typically these objects that will be contained have multiple variables. When an item goes in a container, I could transfer all the item's variables to a table and destroy the object. However, that becomes really, really clunky when it comes to managing the table and trying to parse all the variables that objects might get.

    Alternatively I could turn off all the things that make the item interactive (invisible, non-collideable, etc), and even push them to a different layer, but I'm just not sure if that's the most efficient and "normal" way of going about this.
    I especially want to be thinking of players that may hoard lots of containers with lots of contents in the long run.
     
  2. Gamebot

    Gamebot Member

    Joined:
    Jul 3, 2016
    Posts:
    162
    A persistent parent/control object would be the way to go, you can use a global array or ds_map.... I would go with an array or ds_map anyway. To answer better, the question you are asking is how to do an inventory within many different instances? Or is it a random loot box?
     
  3. FacesOfMu

    FacesOfMu Member

    Joined:
    Jun 23, 2018
    Posts:
    44
    A lot of the guides and tutorials suggest arrays and maps, but the items they're holding are often one dimensional ("sword", "apple", "arrow"). I want to have multiple chests and containers that hold large varieties of items, eg
    Sword, Iron, 5-10 damage, 3 quality, 57 durability, 20min poison duration, ice enchanted, enchantment duration 30 mins, made by Bob
    Salad, 30% left, 5 quality, 30 durability, frozen, made by Bob
    Watering Can, copper, 4 quality, 100 durability, 50% full of blessed water, made by Jane
    etc etc.

    What I want is to do as little parsing and table importing and exporting as possible. I'd really like to maintain these item objects in their instance state and not have to write multitudes of scripts covering moving every item type and their variables into and out of grids or arrays.
     
  4. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    391
    Then nest the DS/array, for example the player's inventory could just be a 2d array that stores type and data. type is just an identifier(string) that tells you how to unpack the data which is another DS/array. That way when moving things to and from the players inventory to chests you just need to copy two array positions directly.
     
    PlayerOne likes this.
  5. Gamebot

    Gamebot Member

    Joined:
    Jul 3, 2016
    Posts:
    162
    As far as the containers themselves are these "randomized" at spawn? If so make a global that separates "Type", "Objects", then max number each object can have.

    Something like:

    Weapons Bobs
    30 12
    Arrow Salad
    Teddy Bear Water Container
    Book other bob stuff


    For each instance in a script get all of the top row randomize them in a ds_list to get random items. Loop through list to find proper max number, choose random number. Now return an array of both to each instance. You can at game end or quit...save all of that to an array. Name the array for that instance the location, x32y52. When you load simply loop through all containers get x and y then add an x and y before each put together and done.
     
    Last edited: Feb 14, 2019
  6. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    340
    I hate them but use ds_grids
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice