Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
hyperPad

hyperPad Forum

  1. Home
  2. Help and Support
  3. Arrays v. Dictionaries

Arrays v. Dictionaries

Scheduled Pinned Locked Moved Help and Support
6 Posts 3 Posters 927 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Michael KhalfinG Offline
    Michael KhalfinG Offline
    Michael Khalfin
    wrote on last edited by
    #1

    I understand what both of them do vey well.

    But why would I use a dictionary over an array? (generally speaking)

    iTap DevelopmentI 1 Reply Last reply
    0
    • Michael KhalfinG Michael Khalfin

      I understand what both of them do vey well.

      But why would I use a dictionary over an array? (generally speaking)

      iTap DevelopmentI Offline
      iTap DevelopmentI Offline
      iTap Development
      wrote on last edited by iTap Development
      #2

      @GameCRAZY you could use it for a shop. The key being the item and the value bing any info(like price) it has.

      The key is the keys!

      Michael KhalfinG 1 Reply Last reply
      0
      • iTap DevelopmentI iTap Development

        @GameCRAZY you could use it for a shop. The key being the item and the value bing any info(like price) it has.

        The key is the keys!

        Michael KhalfinG Offline
        Michael KhalfinG Offline
        Michael Khalfin
        wrote on last edited by
        #3

        @iTap-Development Thanks!

        D 2 Replies Last reply
        0
        • Michael KhalfinG Michael Khalfin

          @iTap-Development Thanks!

          D Offline
          D Offline
          Deeeds
          wrote on last edited by Deeeds
          #4

          @GameCRAZY

          The key advantage (please excuse that VERY lazy pun) is the difference in the method of indexing, and the manner in which they hold and store.

          The disadvantage (sometimes) of arrays is that they're VERY particular about the order things are stored within them, and where you put new content and remove old content from.

          You must address existing locations in an array, or very deliberately insert new items in specific locations, or absolutely replace existing items in the array. Arrays are VERY strict about how they use the memory of the computer, essentially because they're very simple.

          eg. If you have an array of four x (screen) positions, they are stored at index positions 0, 1, 2, 3:

          0: 240
          1: 480
          2: 720
          3: 960
          

          You can't add an item at index location 5. It's simply impossible. You can't even add one at index 4, because that doesn't yet exist. But you can ~append~ item to the array. This extends out the array adding more space for itself, and makes an extra index. Now your new object is stored at index 4.

          And arrays are super sensitive to the order in which things are stored, being absolute sticklers for this detail is both their massive advantage (reliability and predictability) and their short coming, because re-ordering or shuffling an array requires a lot of operations. The order of objects in an array gives it structure and meaning, as you can always be sure that what you want is where you put it, in the order you put everything in, so you can always know what's next... and so can your CPU and memory system.

          Modern computers do an enormous amount of "predictive" processing, and iterating over an array (let's say, adding a 10 to every item in an array) is something that they're VERY good at, as they'll quickly figure out the space between each item and that the iteration is happening, and grab whole chunks of the array early, before instructions come in, and start working on them before being explicitly asked, presuming the results are going to be needed.

          This is of enormous benefits to games, where every frame requires exactly this sort of operation to move all the objects in a game world.

          So if you ever get the chance to use arrays for positions, rotations, interactions, etc... then do. Use them as much as you can.

          In a Dictionary, there is no sense of an index, so objects have no absolute position relative to any other object in the memory or any other form of association. The "location" that each object is stored at only has one rule, that it must be differently named to all the other locations in a dictionary. So you can't have this, for example, a Dictionary with two key names the same:

          A_Key_For: Wooden Door
          A_Key_For: Steal Door
          

          That simply will never work because the Dictionary is absolutely dependent on each key being unique.

          So, instead, you'd name the Dictionary Door Keys and use a Boolean for whether or not you have this key type:

          Wooden_Door_Key: Yes
          Steal_Door_Key: No
          Bank_Door_Key: No
          

          The biggest advantage of a Dictionary is this key, that it can be something meaningful to you and what you're storing. As iTap has said, one of those uses is things that have a volume. So you might have a Dictionary named:

          Soft_Drink_Stock_Dictionary

          Sprite: 3
          Gatorade: 10
          RedBull: 7
          Coke: 5
          Fanta: 6
          

          And you can easily update the number of bottles/cans you have by their key value, and get that amount by using that key, too. Which you can think of as:

          Get Number of Coke in Soft_Drink_Stock_Dictionary
          

          But it's much more powerful than that simple example.

          You can associate two different types of objects, however you need them to be related, and then filter based on their type whenever you need to do an operation. This is maybe somewhat similar to how tags work in @hamed's programming of the background of hyperPad, from a usage point of view.

          A Grocery Store Dictionary of Product Categories might look like:

          Orange:     Fruit
          Apple:      Fruit
          Carrot:     Vegetable
          Banana:     Fruit
          Chicken:    Meat
          Salmon:     Fish
          

          And the order doesn't matter, at all.

          Plus you can throw anything in there, at any time, so long as the new key (which you can choose however you like) is unique.

          And you can delete items from a dictionary and not worry about the order or having an empty location.

          For most everything you need Dictionaries for in a known, static state of data within hyperPad, you can use tags.

          For everything that's changing during gameplay, (running out of whisky) then you're better off using Dictionaries and hand coding their changing state/volume.

          Michael KhalfinG 1 Reply Last reply
          1
          • Michael KhalfinG Michael Khalfin

            @iTap-Development Thanks!

            D Offline
            D Offline
            Deeeds
            wrote on last edited by
            #5

            @GameCRAZY

            A lazy visual metaphor...

            This is an Array:

            https://www.google.co.th/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=0ahUKEwjPlfTM9tfXAhWDsI8KHbUlC4MQjRwIBw&url=https%3A%2F%2Fwww.amazon.com%2FMagazine-G36-Airsoft-Electric-Clip%2Fdp%2FB000NOCVYQ&psig=AOvVaw0ZJhHOw-H9yvdXeLXxheM1&ust=1511637418874135


            And this is a Dictionary:

            0_1511551586260_dictionary.jpg

            1 Reply Last reply
            0
            • D Deeeds

              @GameCRAZY

              The key advantage (please excuse that VERY lazy pun) is the difference in the method of indexing, and the manner in which they hold and store.

              The disadvantage (sometimes) of arrays is that they're VERY particular about the order things are stored within them, and where you put new content and remove old content from.

              You must address existing locations in an array, or very deliberately insert new items in specific locations, or absolutely replace existing items in the array. Arrays are VERY strict about how they use the memory of the computer, essentially because they're very simple.

              eg. If you have an array of four x (screen) positions, they are stored at index positions 0, 1, 2, 3:

              0: 240
              1: 480
              2: 720
              3: 960
              

              You can't add an item at index location 5. It's simply impossible. You can't even add one at index 4, because that doesn't yet exist. But you can ~append~ item to the array. This extends out the array adding more space for itself, and makes an extra index. Now your new object is stored at index 4.

              And arrays are super sensitive to the order in which things are stored, being absolute sticklers for this detail is both their massive advantage (reliability and predictability) and their short coming, because re-ordering or shuffling an array requires a lot of operations. The order of objects in an array gives it structure and meaning, as you can always be sure that what you want is where you put it, in the order you put everything in, so you can always know what's next... and so can your CPU and memory system.

              Modern computers do an enormous amount of "predictive" processing, and iterating over an array (let's say, adding a 10 to every item in an array) is something that they're VERY good at, as they'll quickly figure out the space between each item and that the iteration is happening, and grab whole chunks of the array early, before instructions come in, and start working on them before being explicitly asked, presuming the results are going to be needed.

              This is of enormous benefits to games, where every frame requires exactly this sort of operation to move all the objects in a game world.

              So if you ever get the chance to use arrays for positions, rotations, interactions, etc... then do. Use them as much as you can.

              In a Dictionary, there is no sense of an index, so objects have no absolute position relative to any other object in the memory or any other form of association. The "location" that each object is stored at only has one rule, that it must be differently named to all the other locations in a dictionary. So you can't have this, for example, a Dictionary with two key names the same:

              A_Key_For: Wooden Door
              A_Key_For: Steal Door
              

              That simply will never work because the Dictionary is absolutely dependent on each key being unique.

              So, instead, you'd name the Dictionary Door Keys and use a Boolean for whether or not you have this key type:

              Wooden_Door_Key: Yes
              Steal_Door_Key: No
              Bank_Door_Key: No
              

              The biggest advantage of a Dictionary is this key, that it can be something meaningful to you and what you're storing. As iTap has said, one of those uses is things that have a volume. So you might have a Dictionary named:

              Soft_Drink_Stock_Dictionary

              Sprite: 3
              Gatorade: 10
              RedBull: 7
              Coke: 5
              Fanta: 6
              

              And you can easily update the number of bottles/cans you have by their key value, and get that amount by using that key, too. Which you can think of as:

              Get Number of Coke in Soft_Drink_Stock_Dictionary
              

              But it's much more powerful than that simple example.

              You can associate two different types of objects, however you need them to be related, and then filter based on their type whenever you need to do an operation. This is maybe somewhat similar to how tags work in @hamed's programming of the background of hyperPad, from a usage point of view.

              A Grocery Store Dictionary of Product Categories might look like:

              Orange:     Fruit
              Apple:      Fruit
              Carrot:     Vegetable
              Banana:     Fruit
              Chicken:    Meat
              Salmon:     Fish
              

              And the order doesn't matter, at all.

              Plus you can throw anything in there, at any time, so long as the new key (which you can choose however you like) is unique.

              And you can delete items from a dictionary and not worry about the order or having an empty location.

              For most everything you need Dictionaries for in a known, static state of data within hyperPad, you can use tags.

              For everything that's changing during gameplay, (running out of whisky) then you're better off using Dictionaries and hand coding their changing state/volume.

              Michael KhalfinG Offline
              Michael KhalfinG Offline
              Michael Khalfin
              wrote on last edited by
              #6

              @Deeeds Thank you so much! That is very helpful!

              1 Reply Last reply
              0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Search