Getting a Dictionary value using an instance variable as key

Get help using Construct 2

Post » Wed Feb 04, 2015 10:13 pm

I created a capx as an example of the question I have:
bunny_dictionary.capx


I understand that you can get the key/value from a dictionary by using:

Dictionary.Get("")

I'm wondering if it is possible to get the key/value by using an instance variable value of an object. For example in the capx I posted I have a sprite that is named bunny. The bunny has 2 instance variables, one which is "type". Can you only use this method with a global/local variable or should you be able to use:

Dictionary.Get("bunny.type")

Using the instance variable does not work in my example but I have been able to get it to work with a global variable.
You do not have the required permissions to view the files attached to this post.
B
7
S
1
G
1
Posts: 13
Reputation: 422

Post » Wed Feb 04, 2015 10:28 pm

Just remove the quotes around bunny.type
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Feb 04, 2015 10:45 pm

if you want to have the variable of an Instance than just type:
bunny.type

If you want to store it in a Dictionary and get it out later, you need to create a key at first:
Dictionary: Add key "thetypeofbunny" with value bunny.type (no quotes)

If you want to call it you make:
Dictionary.Get("thetypeofbunny")
Read this:
yeah, i really like to say that you should "Read this:"
B
14
S
7
Posts: 138
Reputation: 1,740

Post » Wed Feb 04, 2015 10:49 pm

@codah I just tried that in the example I posted and it doesn't work. Can you try with my example capx and see?
B
7
S
1
G
1
Posts: 13
Reputation: 422

Post » Wed Feb 04, 2015 10:55 pm

jstar wrote:@codah I just tried that in the example I posted and it doesn't work. Can you try with my example capx and see?


I assumed you knew how to do the rest in your actual code :) Have a look at the @EyeForcz post. You probably don't want to add instance variables to your Dictіonary like that.. what are you trying to achieve?

edit: oh ok, try this
You do not have the required permissions to view the files attached to this post.
Last edited by codah on Wed Feb 04, 2015 11:09 pm, edited 3 times in total.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Feb 04, 2015 10:56 pm

@jstar codahs methode dont work because you havent set a key for it. If you just want to call a instance variable you just type bunny,type and dont need a dictionary for that.
Read this:
yeah, i really like to say that you should "Read this:"
B
14
S
7
Posts: 138
Reputation: 1,740

Post » Wed Feb 04, 2015 11:01 pm

I've updated the capx, see if it's what you want.

edit: note the 'add key' lines should be out of the loop :) Updated.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Feb 04, 2015 11:10 pm

@codah and @eyeforz

***EDIT*** I saw the capx you posted after I made this post and it makes sense now

I had followed a bad example of how to properly use Dictionaries key/value pairs
Last edited by jstar on Wed Feb 04, 2015 11:15 pm, edited 1 time in total.
B
7
S
1
G
1
Posts: 13
Reputation: 422

Post » Wed Feb 04, 2015 11:14 pm

Here is the working Capx, i just added a Text instance to show the result:

Update: if you want to get the numbers out of the dictionary you use this methode:
Dictionaty.dwarf without the get. Dictionary.Get("") is for keys the Dictionary.dwarf would be a Instance Variable they are 2 different things, you must be carefull with that.
You do not have the required permissions to view the files attached to this post.
Last edited by EyeForcz on Wed Feb 04, 2015 11:23 pm, edited 2 times in total.
Read this:
yeah, i really like to say that you should "Read this:"
B
14
S
7
Posts: 138
Reputation: 1,740

Post » Wed Feb 04, 2015 11:19 pm

my question was answered by @codah

Thanks to you both!!!
B
7
S
1
G
1
Posts: 13
Reputation: 422

Next

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 10 guests