League of Legends API, .JSON file & AJAX problem

0 favourites
  • 14 posts
From the Asset Store
Basketball league takes the basketball free throw game to a whole fun & addiction! Play C3 Basketball Tournament with Z
  • Hello guys!

    I have a question. It's very important. I'm just starting my adventure with Construct 2, but already I came across a pretty big problem that I can not solve.

    As you know, the League of Legends has it's own API.

    After generating a URL, it looks like this:

    {"micheal23":{"id":40904801,"name":"Micheal23","profileIconId":26,"summonerLevel":1,"revisionDate":1363260127000}}

    That is what server returns (.JSON file? - I think so.. Tell me if I'm wrong)

    I want to choose specific data (but dynamically) - ID, USERNAME, PLAYER'S LEVEL and place it in Construct 2. The only question is how to do it?

    I tried to use Ajax, but he asks me the value of parentheses and apostrophes, and I want to make it look less like this:

    ID: 40904801

    Name: Michael23

    Level: 1

    I just want to put a clear informations to textbox in C2. Please help. I found a few plugins ("How to read the .json file"), but I want to do it dynamically from League of Legends server (to use what data request give me back).

    Thanks!

  • https://www.scirra.com/forum/plugin-json-import-export-generate-edit-inspect_t100042?&hilit=JSON

    Here is a plugin designed to sort JSON text. As far as I know there is no way for C2 to pull data directly off of LOL's server. AJAX will call a file but it only pulls the text of a file with no native way for it to understand what it just pulled. It then is either put in a Array or Dictionary object that you can then sort though. Again think of AJAX as the messenger, it just brings the news you then have to use it. Yanns JSON plugin would work great once you get use to working with it. Just use AJAX to call the URL that you want and then load it into a JSON object. Then with a text object you just need to have it <set text> of what you want. also may want some global variables to make it essayer like varID, varName and varLevel. Just when you set up your data set each variable to what your need.

    "ID: "&varID&newline&"Name: "&varName&newline&"Level: "&varLevel
    [/code:25xzk0xt]
    
    Remember the & is the text object that allows you to string more then one type of data together
  • {"19141338":"vagrant8"}

    I do not know how to do this, really!

    I read a little bit about using a dictionary and arrays, but I stuck at this point..

    Could you show me on example (.capx) how to draw values that interest me? Help me, please!

    Only one example (not all values). I need it.

    Thanks a lot one more time!

  • Did you install the JSON plugin that CrazyVulcan linked to? You can use the LoadJSON action of the JSON plugin to load in AJAX.LastData. Then the expression JSON.Value(0, "19141338") will return "vagrant8".

  • like to share a tool which would help for JSON lovers jsonformatter.org

  • jasminm Thanks for help, but I want to do it dynamically , directly in the Construct 2.

    ramones Yes, I installed the plugin, but it seems to me that it doesn't work..

    What if I want to write the name of player not using his ID, but only by name tag?

    I plan to make an application that after entering a player's name will automatically download the Riot API information - all statistics and rest of the stuff, you know.

    Could someone show me how to use this plugin (on .capx)? One small example. The rest I will do likewise.

    Thank you very much!

  • It's look like this.

    Chrome sends an error message. It's probably JavaScript thing (browser suggesting that, so this may be the plugin or behavior) and the program returns "undefined" property..

    I have no idea!

  • You are trying to load ajax.lastdata before the Ajax is completed..

  • {"19141338":"vagrant8"}

    If this is what the textobject shows and you are setting it to ajax.lastdata as shown in the picture, this is all the ajax-request gets..

    (That is if the textobject is big enough to show the complete ajax.lastdata)

  • [quote:1p1fp8va]You are trying to load ajax.lastdata before the Ajax is completed..

    I'm sorry. I didn't notice a stupid mistake. You're right!

    Now .json file is loaded when AJAX does his job.

    But "Set Text JSON.Value (0, "19141338")" is not working. JavaScript - OK, but the program still shows "undefined" property.. So close!

  • I guess you should first check if the json you recieve is what you expect..

    easy way would be to set one textobject to ajax.lastdata on ajax completed..

  • [quote:1wsktpui]easy way would be to set one textobject to ajax.lastdata on ajax completed..

    I've done that before.. like.. you know.. 100 times, and AJAX receives the correct values.

    The problem must be somewhere when C2 reading .JSON data using the plugin Here is my .capx file.. .

    https /view?usp=sharing

    Could you see what I'm doing wrong?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You have two JSON objects. You're loading the data into one of them but trying to read it from another

  • Okay This is helpful tip, but I still don't know what I should do, if I want to Construct 2 return to me a "vagrant8" value.

    Could you correct my .capx file?

    Please!

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