How do I use .JSON to store data and write?

0 favourites
  • 6 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Ive been scouting around for solutions, im wondering, if i for example, have a level on my character, and a name, i would like to have this in a db for the player, so it can load next time he logs in, and so it can be altered on my website instead of my app. so, first question,

    if i want to create a variable in .JSON , called characterlvl , and if i would like to use execute json commands to add or substract from the value inside this .json data file, is this possible?

    also i have a hard time understanding where to put the Access-Control-Allow-Origin: * when i use the AJAX plugin, tips?

  • Saving data to your web application requires server-side development, for example, using PHP and MySQL. Someone asked a similar question here: https://www.construct.net/en/forum/construct-2/how-do-i-18/newbie-question-on-load-save-d-58990. I’m not finding a Construct 3 tutorial but the ideas are the same.

    To avoid server-side development, you could look at services like Firebase or Parse, or PlayFab or GameSparks. I don’t know of any Construct 3 plugins for these now, other than maybe ‘s Firebase plugins: https://chadorirebornxd.itch.io/construct-master-collection

    And about access-control-allow-origin, it’s one of those many server-side details. In a nutshell, it’s only needed when your game (html & scripts) loads from a different website (e.g., site A) than your web api server (site B). It’s set as an http header on your api app, allowing your site A app to make Ajax calls to site B. I think all of the hosted services, like Firebase, allow you to configure it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've seen that plugin and I'm planning to buy it. I have a wamp server running with php and mysql. Im trying to figure out how to use my website with construct 3.

    I have the html element plugin for ex posting or getting from sql dB since that's the language in know and php. Imagine a browser rpg game with users etc...

    And about access-control-allow-origin . Should I leave this for now or do I put it in the index file how do I add this and where ?

    Thank you for your reply I understand a lot more now ! You don't have to answer the questions that was just what was in my mind. About the plugin I'm definitely getting it. It has all the comforts plugins it seems

  • Sami, okay good! If you’re doing your own server-side dev, then you may only want to use the built-in AJAX plugin in Construct to do POSTs and GETs. That said, I am looking at PlayFab to get all of those services...

    And you can forget about that http header, as long as you’re loading the game from the same domain as your web app. But Google that term and you’ll find some good explanations, e.g., https://en.m.wikipedia.org/wiki/Cross-origin_resource_sharing. But I swear I’ve run into cases where a firewall, on a college network, didn’t allow cross-origin ajax calls even with the needed Access-Control-Allow-Origin header set.

  • Thank you for The help! What does Play FAB include that is good for me and my plans, if i am running my own server already? Just wondering since my plan is to use sort of mysql dB, since in school im working with html, php and mysql, do you have Any tip on how i would connect to The SQL DB? I could try to paste The include mysqllogin.php in the index.html , i Will try this.

    And for The origins thanks a very good explanation, i Will leave it alone for Now.

    And The last question, if i store These AJAX files in my Web server, is it not a security risk for cheaters to easy execute JavaScript to for ex. Get more gold? Im new at JSON

    Edit : checked out The link and now i understand that what i want is possible, The tutorial on php SQL and c2 worked for c3 aswell. Thank you very much!

    Thank you for your reply

  • This is a basic example of how to interact with Ajax, PHP and Mysql.

    It will show you how to make a Online Highscore Table, that interacts with C2/C3 variables.

    https://www.scirra.com/tutorials/346/online-high-score-table-ajax-php-mysql

    Just as a side note, to work in preview in C3 you need to use a secure server (HTTPS), otherwise you will have to export it to see it working.

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