Advanced C2 - Building a Online Browser Game With C2

Get help using Construct 2

Post » Sun Apr 19, 2015 4:46 pm

@CrazyVulcan

Use @Yann 's JSON plugin to parse JSON string.
B
107
S
25
G
231
Posts: 4,360
Reputation: 131,410

Post » Sun Apr 19, 2015 5:14 pm

rexrainbow wrote:@CrazyVulcan

My firebase plugins only could work on firebase service.
There are some services like parse which supports datebase-in-service.


https://www.scirra.com/forum/plugin-parse-cloud-data_t115108

So far this was the only plugin that looked like what I am wanting but the pricing is waaay out of my budget. And considering I can probably do much of that myself given time and a point in the right direction I need to look at other options

Any one have any suggestions. I can do the coding myself if necessary and learning is not a issue. But I don't know exactly what I need to do first.

Lets start with how do you call a database table in AJAX?

-edit-
Rex, thanks this seems to be something I can use. I will need a bit of time to learn it first but I dont see why it wont work. Downloading now
"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
2
Posts: 113
Reputation: 1,245

Post » Sun Apr 26, 2015 9:36 pm

I posted this on Yanns page but mabe someone here can help,

I seem to be having a issue with C2 working with JSON data. I am simply trying to load a JSON raw into your plugin
Code: Select all
{
"Bob":{
     "Skill1":"AA",
     "Skill2":"BA",
     "Skill3":"CA"},
"Ted":{
     "Skill1":"AB",
     "Skill2":"BB",
     "Skill3":"CB"},
"Mike":{
     "Skill1":"AC",
     "Skill2":"BC",
     "Skill3":"CC"}
 }


What is wrong with this syntax? The first "{" has a red line under it so there has to be something wrong with how I am wighting this JSON. Your plugin seems to be just exactly what I need but I have no clue as to why my code is getting this error.

I'm sure its something that I am doing stupid

I can get it to work by changing it to

Code: Select all
"{
""Bob"":{
     ""Skill1"":""AA"",
     ""Skill2"":""BA"",
     ""Skill3"":""CA""},
""Ted"":{
     ""Skill1"":""AB"",
     ""Skill2"":""BB"",
     ""Skill3"":""CB""},
""Mike"":{
     ""Skill1"":""AC"",
     ""Skill2":""BC"",
     ""Skill3"":""CC""}
 }"


But then its not a JSON and having too many " means just that much more likely that I will miss one and screw the whole thing.
"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
2
Posts: 113
Reputation: 1,245

Post » Mon Apr 27, 2015 9:09 am

If you are putting the JSON into the C2 event sheet directly it has to be a string enclosed in quotation marks and so you have to escape any quotation marks inside the string with an extra pair. That's fine. If you load the JSON from a file, you don't need the extra quotation marks.
B
55
S
28
G
19
Posts: 1,520
Reputation: 25,540

Post » Tue Apr 28, 2015 4:04 am

ramones wrote:If you are putting the JSON into the C2 event sheet directly it has to be a string enclosed in quotation marks and so you have to escape any quotation marks inside the string with an extra pair. That's fine. If you load the JSON from a file, you don't need the extra quotation marks.


Thanks @ramones, AJAX is still something I am trying to get a handle on. I have the next two days off so I intend to get this nailed down by Thursday. Is their a particular way C2 wants to JSON formatted when it is brought in through AJAX? I have tried putting in a file in my projects folder and using Yann's plugin just use that to load the JSON. It however gives me errors when I try it. I will try to post a capax of what I am saying. That should help.

I have tried pulling the file as both a .txt and .json with little success though in my browser preview debug I did see where AJAX managed to load the text. But getting that text to work with that plugin has been a we bit of a headache.

Do I just have a .txt file with {"ThingOne":{"A":"1","B":"2"},"ThingTwo":{"Y":"1","Z":"1"}} ?

I promise once this clicks I will wright a nice in depth tutorial about handling JSON as I can find little on it. This either means its not a common thing or its so simple that most assume that everyone knows it.

!-- Edit

Yey ok so I managed to get the AJAX to load into the JSON Plugin. Don't know what was not going right. Maybe just needed to look at it with tired eyes after a long shift, usually when I do my best work anyway. :lol:
"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
2
Posts: 113
Reputation: 1,245

Post » Wed Apr 29, 2015 12:23 am

OK I have a interesting issue as I dont seem to understand how pathing works. After much effort I have finally managed to get WebMatrix and Google Chrome to run locally and now don't need to upload to a external server every time I wish to run my game. Now there are just two things left for me to understand and then I feel I can move on.

First, I have managed to use AJAX and get it to load a JSON from my project file just fine and now need the next step. I need to be able to pull this JSON from a folder that contains the website, C2 Game, and the database. Currently my folder hierarchies looks something like this

Code: Select all
[My Game]
     [Images]
     index.html
[UserData]
     MyData.json
index.html
gamewindow.html
mainCSS.css
gamewindow.html


So naturally my site launches index.html and there is a link that takes you to gamewindow.html that has a iframe embedded to play index.html form within the folder [My Game]. Right now my game plays just fine but I cant seem to figure how AJAX finds the MyData.json in the folder.

I have tried
"http://localhost:50000/Debug.json" As well as "http://localhost:50000/Desktop/MyGame/UserData/Debug.json"
"http://localhost:55707/Debug.json" (which is the port number showing up when I look at my website in WebMatrix. My thinking is that since the game index.html is in a sub folder and I need to get at a different folder I have tried "http://localhost:50000/../UserData/Debug.json" So what is it that I am missing? Where dose the file path start. I have looked over the tutorial https://www.scirra.com/tutorials/393/ajax-in-local-preview-on-localhost50000

His example simply says "http://localhost:8080/scirraTest/myGame/xml/dataIWantToGet.xml" But where would "scirraTest" reside? The Desktop? the C:drive?
"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
2
Posts: 113
Reputation: 1,245

Post » Wed Apr 29, 2015 9:45 am

It's whatever the root folder for your server is configured to. It depends what server you are running. Basically it's the folder you're exporting your project to. If that top-level index.html is at http://localhost/index.html then the JSON file would be http://localhost/UserData/MyData.json.
B
55
S
28
G
19
Posts: 1,520
Reputation: 25,540

Post » Wed May 06, 2015 7:30 pm

https://www.dropbox.com/s/vhx888s3cpvtuj8/WebDebugAJAX.capx?dl=0
https://www.dropbox.com/sh/yfum8cnri1vzmoc/AACwvUPc0vqiFC6HDDak2ju7a?dl=0

ramones wrote:It's whatever the root folder for your server is configured to. It depends what server you are running. Basically it's the folder you're exporting your project to. If that top-level index.html is at http://localhost/index.html then the JSON file would be http://localhost/UserData/MyData.json.


I really need to quite my day job so I can focus on this game dev shtick full time. :?

So have you ever done something that you have tired to do for a good amount of time and then call it a night after feeling good. Only to come back a week later and have no idea what the hell you just did? Well now I do because I have managed to get the AJAX to see my file but then now after coming back to it, it will not work. Above is a Dropbox link for my capax and a folder that I am using for a web site. the package.json is the file I am trying to call but for the life of me I can not get the plug in to find it even though I have it sitting in the same folder as my index.html for the C2 Game.

Here is my event sheet, ignore the Big A as that is just something I change the color of to see if my update was successful. The capax is a new file that has been striped of all the fluff not related to AJAX.
https://www.dropbox.com/s/ug4otfz4210tvp4/C2error01.png?dl=0
https://www.dropbox.com/s/ard8964th040wp7/C2error02.png?dl=0

Some guidance would be most welcomed. I am mostly sure that my URL for the AJAX is wrong. That and I see that a Error 404.3 involves needing to set a MIME type but I am haveing toubble finding on what that means and what I need to do. Also there really is not a guide in this site that plainly says for a AJAX you must do A>B>C and for me that is really hard because I feel that this is something so simple to under stand that no one has felt the need for such a tutorial.

ps what happened to being able to post attachments?
"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
2
Posts: 113
Reputation: 1,245

Post » Wed May 06, 2015 8:06 pm

Edit: You need to import you json file into your project.

From what I understand.
You want to get data in a json file into your game using ajax?

In your projects window you want to import files - in your case it would be your json file. It will now save it allong with the c2 icons. If you save project as project you will see it there. And you can edit it directly. {C2 saves as single or project, project allows you to edit files within the folder structure directly}

Ajax is simple. You request a file dropdown will list files you've imported and tag it with a easy to remember name "MyAwesomeData"
The trick is ajax on "MyAwesomeData" completed, this means it has all your juicy data.
Now you can load from json string using AJAX.LastData to either array or dictionary ect.

Ajax request "your json file you imported into project"
Ajax on completed, load json string ajax.lastdata.

I don't know if this will help: load data from json into array

So, import you json file into the project. and it will save it under Files folder ;)
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,698

Post » Thu May 07, 2015 5:23 am

DUTOIT wrote:Edit: You need to import you json file into your project.

From what I understand.
You want to get data in a json file into your game using ajax?

In your projects window you want to import files - in your case it would be your json file. It will now save it allong with the c2 icons. If you save project as project you will see it there. And you can edit it directly. {C2 saves as single or project, project allows you to edit files within the folder structure directly}

Ajax is simple. You request a file dropdown will list files you've imported and tag it with a easy to remember name "MyAwesomeData"
The trick is ajax on "MyAwesomeData" completed, this means it has all your juicy data.
Now you can load from json string using AJAX.LastData to either array or dictionary ect.

Ajax request "your json file you imported into project"
Ajax on completed, load json string ajax.lastdata.

I don't know if this will help: load data from json into array

So, import you json file into the project. and it will save it under Files folder ;)


Hi @DUTOIT

Unfortunately my project requires that I be able to edit and replace elements of that JSON and then post them back to a file that is unique to each player. While I have been successful in loading it as a project file as you have described above C2 will not allow you to post changes back to the project file. And I can not use web data as this game will involve a in app store and having that data stored local on a players computer leaves too much to be tampered with. I cant have cheaters ruining my game for not only dose it hurt the paying player but that is money lost 8-)

I need to work out how the URL works and how it will find the exact folder I want. I have the cross domain problem solved with a tool for chrome and am able to deploy this site to Azure. But I am stuck on the exact path the AJAX looks up. I can have "http://localhost/PlayerData/"&PlayerID&".json" That PlayerID is a global variable that will allow me to call their own files. Which will be stored in a database table and when you login to my site it will make a MySQL call and get that JSON in question.

But I appreciate the help.
Just got back from work and am trying to remember what I was working on before I left. I believe I was researching the 404.3 error and doing something with enabling IIS on my computer or something like that but I really don't want to leave myself open to hacking.

Any one familiar with Webmatrix3? Im thinking about asking on their forum but am trying to see if I can not solve my issues first. They most likely will know nothing about Construct any way.
"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
2
Posts: 113
Reputation: 1,245

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: imhotep22, LunchboxGames and 6 guests