Missing something using dictionary object (see image)

0 favourites
  • 10 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I was doing some simple tests with the dictionary object and I immediately ran into a snag. (See image below.) When I click the button on my form the text string changes to "0". What am I doing wrong?

    NOTE: I included a picture of the debugger. The dictionary object has the correct data, I just can't seem to retrieve it using the key value "Name".

  • Can you log the JSON string that you receive to the console ? Without this it's impossible to know what the problem is.

  • Thank you for the reply, Zed!

    Here is the JSON string from Ajax.LastData:

    {
    	"c2dictionary": true,
    	"data": {
    		"\"Name\"": "\"John\"",
    		"\"Age\"": 32,
    		"\"last_played\"": 0,
    		"\"puzzles_lost\"": 0
    	}
    }[/code:zs15n2r5]
    
    I created the json file within Construct 3. I right clicked on the "Files" button and chose "New" & "Dictionary". Then I just entered some values:
    
    "Name" = "John"
    "Age" = 32
    "last_played" = 0
    "puzzles_lost" = 0
  • I just did the same test on my end and it works just fine. I get "John" when I do Dictionary.Get("Name").

    Try this: forget about the form for now, try to directly print Dictionary.Get("Name") to the console after loading the dictionary.

  • Try this: forget about the form for now, try to directly print Dictionary.Get("Name") to the console after loading the dictionary.[/code:3d55xobx]
    
    To be honest, I'm not sure how to do that. I need a plugin, right?
    
    As a test I just started completely over with fresh code and tried setting a Global String variable to Dictionary.Get("Name"). I tried triggering this based on a button press (the debugger says the value of the variable was still "O"), then I moved it below the line where the dictionary loads AJAX.LastData. The debugger still says "O".
    
    I'm stumped.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Post a CAPX.

  • [quote:2dwry3bw]Post a CAPX.

    As I mentioned, I built my dictionary test using Construct 3. (But the file is small enough for people with the FREE version to view.)

    dictionary_test.c3p

    https://ufile.io/hk7a1

    UPDATE:

    I just tried adding keys to my dictionary manually, and that worked as intended. Here's the code:

    So I seem to be having an issue when I use Construct 3 to generate my dictionary file. I'll put up a new post in the Construct 3 area.

  • Update: blackhornet provided the solution to my problem! When I entered the data in the JSON file (using Construct 3 I was able to type values into a table) I was using quotation marks for strings. Apparently, this isn't necessary. When I removed them everything worked correctly.

    In case anyone else runs into this issue in the future I made a quick illustration:

  • If this is for C3, why post in the C2 section?

    If a mistake, just tag any mod and ask them to move the thread.

  • [quote:1blze4vj]If this is for C3, why post in the C2 section?

    Yeah, sorry about that. I initially posted in the C2 section because more people seem to read that section. When I realized my problem was specific to C3 I posted again there, then found out it was too late for me to delete this thread. Can you do that for me? Thanks!

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