KuJoe's Forum Posts

  • > hopefully it's just something I'm doing wrong on my end.

    >

    Wrong Json format!

    Dictionary or Associative array

    [quote:226gkk3r]The Dictionary object stores strings and numbers. Each value has an associated key

    "name": "Joe"

    "score": 100

    my example:

    {
    	"c2dictionary": true,
    	"data": {
    		"0": "13,1,KuJoe",
    		"1": "14,2,Tester Bot",
    		"2": "16,4,Shadow",
    		"4": "17,"6",Tinner"
    	}
    }[/code:226gkk3r]
    
    your json:
    [code:226gkk3r]{
    	"c2dictionary": true,
    	"data": [
    		["13","1","KuJoe"],
    		["14","2","TesterBot"],
    		["15","3","Hello"],
    		["16","4","Shadow"],
    		["17","6","Tinner"]
    	]
    }[/code:226gkk3r]
     you don't have keys inside "data"..but muliple arrays...
    so  you can't access dictionary data...
    
    
    Thanks, I'm still trying to wrap my head around the formatting for Construct 2 and I'm not strong  with JSON as it is. I was under the impression that Construct 2 would reject the JSON if it was bad like it does for Arrays. I'll look into trying to figure out how to get my PHP file to format it correctly now. Thanks again.
  • helloAjax.capx

    This capx works correctly but if I replace the TXT file with the remote PHP file it doesn't work. I've opened a bug report here for anybody else who comes across this issue (hopefully it's just something I'm doing wrong on my end).

  • Problem Description

    Attempts to use tokenat on a Dictionary via the "For each key" event doesn't work with the dictionary.CurrentValue when I populate the Dictionary with a JSON string from a remote PHP file (via AJAX). Confirmed the code is working if I load the data from a local TXT file, loading the data from a remote PHP file don't work though.

    (Related thread: https://www.scirra.com/forum/how-do-i-use-tokenat-on-dictionaries_t184524)

    Attach a Capx

    http://n3rd.info/dictionary_tokenat_bug.capx

    Description of Capx

    1) AJAX request to a remote PHP file to get JSON formatted output of a MySQL database.

    2) Load the JSON string into a Dictionary object.

    3) Loop each Dictionary key and append the 2nd token from the CurrentValue of each key to a Text object.

    Steps to Reproduce Bug

    • Open the capx file and watch the output (no manual steps required).

    Observed Result

    Loops each key and outputs "Hello " but does not output the 2nd token like it's supposed to.

    Expected Result

    Output should be "Hello <name>" 5 times.

    Affected Browsers

    • Chrome: YES
    • FireFox: UNKNOWN (Not Installed)
    • Internet Explorer: YES
    • Edge: YES
    • Midori: YES

    Operating System and Service Pack

    Windows 10 Pro 64bit

    Construct 2 Version ID

    Tested in both r239 stable and r240 beta

  • Do you have more than one playerDB object? I tried a similar example, that worked for one dictionary, but if I create a second, the tokenat code shows blanks. If I add a Foreach palyerDB above the For each key, it then works.

    I had another Dictionary but I deleted it after creating the 2nd one. I tried the "Foreach" above the "Foreach Key" and it didn't work. Probably a bug.

  • helloAjax.capx

    Yeah, looks like I'm running into a bug.

  • try

    "Hello " & tokenat(playerDb.Get(playerDb.CurrentKey),2,",")[/code:mobn2m4u]
    

    Nope, still the same output.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm stumped, I've been searching for a while now and all of the threads on the forum that include examples of tokenat make me think my code would be working but alas it's not. I'm using AJAX to grab JSON output from a PHP file (from MySQL) and loading the data into a Dictionary, but all attempts to pull any data from any Dictionary value is not working.

    My code:

    My Dictionary keys/values:

    The output:

    I'm not sure if it's the last of sleep or what but this doesn't make sense to me.

    (I'm using the latest stable version of Construct 2 if that matters.)