Why do dictionaries have instance variables?

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi.

    I have created a dictionary but then I discovered instance variables can be used on dictionaries as well?

    Instance variables are cool on created sprite objects, but why use a key in a dictionary, instead of just creating an instance variable on the dictionary?

    If you use a key on your index, you have to remember the key string, but if you use instance variables, you have "code completion" when you create your events.

    So which is best? instance variables or keys on dictionaries?

  • You can fill up the dictionary with key:value pairs, look if keys exist etc.

    You can't add instance variables as your program runs.

    So... they offer different functionalities. Use what seems most practical to you for each problem. Most of the times it will probably be instance variables, but that doesn't mean that dictionaries don't have their uses.

  • Dont forget a key word here, instance.

    You can create multiple instances of them, and use the variable for picking, ...for instance.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you want each object to have its own dictionary, that would be possible with containers, too, though (if I am not mistaken). I'm not saying "you should", just "you could".

  • What i am confused about, is that you can put instance variable on a dictionary, which is a container for objects.

    But ok, I understand that this is just an option.

  • They have instance variables, for the same reason other object types have instance variables.

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