KuJoe's Recent Forum Activity

  • Turns out the problem was me not setting the key values even though they were automatically filled in with numbers. Consider this thread solved.

  • This can be marked as closed. It looks like the problem was me not setting the key value in my PHP output even though it automatically filled in the key values with numbers.

  • The JSON output by your php script doesn't look like the JSON that is written by the dictionary object. Your JSON looks like this:

    > {
    	"c2dictionary":true,
    	"data":[
    > 		["13","1","KuJoe"],
    		["14","2","TesterBot"],
    		["15","3","Hello"],
    		["16","4","Shadow"],
    		["17","6","Tinner"]
    	]
    }
    [/code:2qkpa78c]
    
    Sample of working JSON that I'm using in one of my own projects:
    [code:2qkpa78c]
    {
    	"c2dictionary":true,
    	"data":{
    		"100":"Course 1 Entrance",
    		"101":"Course 1-1",
    		"102":"Course 1-2",
    		"103":"Course 1-3",
    		"104":"Course 1-4",
    		"105":"Course 1-5",
    		"106":"Course 1-6",
    		"107":"Course 1-7",
    		"108":"Course 1-8",
    		"109":"Course 1-9",
    		"110":"Course 1-10"
    	}
    }
    [/code:2qkpa78c]
    
    I'm not terribly well versed in JSON, but it appears you are using arrays instead of a key-value relationship, like the Dictionary expects.
    

    Somebody else pointed this out also which is strange because when I have a malformed JSON output and try to insert it into an Array it won't accept it. The fact that the Dictionary is accepting it (and the debug shows that the Dictionary is apparently populated correctly) has me confused. I wish there was an up-to-date example for formatting JSON output from remote files since all of the old solutions don't appear to work.

  • > 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 Construct 3

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

    Try Now Construct 3 users don't see these ads
  • try

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

    Nope, still the same output.

  • 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.)

KuJoe's avatar

KuJoe

Member since 8 Sep, 2016

None one is following KuJoe yet!

Trophy Case

  • 8-Year Club
  • Jupiter Mission Supports Gordon's mission to Jupiter
  • RTFM Read the fabulous manual
  • x2
    Quick Draw First 5 people to up-vote a new Construct 3 release
  • Email Verified

Progress

12/44
How to earn trophies