League of Legends API, .JSON file & AJAX problem

Get help using Construct 2

Post » Tue Nov 03, 2015 3:14 pm

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? :geek:
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!
B
5
Posts: 22
Reputation: 255

Post » Tue Nov 03, 2015 4:10 pm

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.

Code: Select all
"ID: "&varID&newline&"Name: "&varName&newline&"Level: "&varLevel


Remember the & is the text object that allows you to string more then one type of data together
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
3
Posts: 113
Reputation: 1,295

Post » Tue Nov 03, 2015 5:47 pm

Image

{"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!
B
5
Posts: 22
Reputation: 255

Post » Tue Nov 03, 2015 8:45 pm

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".
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,680

Post » Wed Nov 04, 2015 8:01 am

like to share a tool which would help for JSON lovers jsonformatter.org
B
2
Posts: 2
Reputation: 158

Post » Thu Nov 05, 2015 5:57 pm

@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.. :cry:

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! ;)
B
5
Posts: 22
Reputation: 255

Post » Thu Nov 05, 2015 7:07 pm

Image
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!
B
5
Posts: 22
Reputation: 255

Post » Thu Nov 05, 2015 7:13 pm

You are trying to load ajax.lastdata before the Ajax is completed..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Nov 05, 2015 7:18 pm

flementh wrote:{"19141338":"vagrant8"}[/b] :|


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)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Nov 05, 2015 8:46 pm

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!
B
5
Posts: 22
Reputation: 255

Next

Return to How do I....?

Who is online

Users browsing this forum: Akia410, katzin and 8 guests