Why do dictionaries have instance variables?

Just started using Construct 2? Post your questions here

Post » Wed Nov 12, 2014 11:05 pm

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?
B
5
S
1
Posts: 59
Reputation: 493

Post » Fri Nov 14, 2014 9:21 pm

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.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Fri Nov 14, 2014 10:29 pm

Dont forget a key word here, instance.
You can create multiple instances of them, and use the variable for picking, ...for instance.
Image ImageImage
B
168
S
50
G
163
Posts: 8,222
Reputation: 105,063

Post » Fri Nov 14, 2014 11:56 pm

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".
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Sat Nov 15, 2014 10:38 am

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. :-)
B
5
S
1
Posts: 59
Reputation: 493

Post » Sat Nov 15, 2014 12:54 pm

They have instance variables, for the same reason other object types have instance variables.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests