Advanced C2 - Building a Online Browser Game With C2

0 favourites
From the Asset Store
A cool way for kids to write and practice English Alphabets
  • 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

    [My Game]     [Images] 
         index.html 
    [UserData] 
         MyData.json 
    index.html 
    gamewindow.html 
    mainCSS.css 
    gamewindow.html 
    [/code:3t27umc3] 
     
    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 [url]https://www.scirra.com/tutorials/393/ajax-in-local-preview-on-localhost50000[/url] 
     
    His example simply says "http://localhost:8080/scirraTest/myGame/xml/dataIWantToGet.xml" But where would "scirraTest" reside? The Desktop? the C:drive?
  • 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.

  • https://www.dropbox.com/s/vhx888s3cpvtuj8/WebDebugAJAX.capx?dl=0

    https://www.dropbox.com/sh/yfum8cnri1vzmoc/AACwvUPc0vqiFC6HDDak2ju7a?dl=0

    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?

  • 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

  • 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

    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.

  • So save the json data into a mysql database entry

    User Id | Userdata string

    The url is a post/get system it can send the id to a php file which retrievs the data string shouldn't that work better having it saved in a database vs tons of json files lying all over the place

  • So save the json data into a mysql database entry

    User Id | Userdata string

    The url is a post/get system it can send the id to a php file which retrievs the data string shouldn't that work better having it saved in a database vs tons of json files lying all over the place

    DUTOIT yes that is my eventual goal, and my trouble is not making a form to store the json's. More that once they are in the database how do I "see" them with ajax. What exactly do I need to put in that url to find the specific json I am looking for.

    I need to learn how to have C2 find that string. My thinking is to have a javascript in the head of the index.html file of my game that will pull the table based on the UserID that the player has after they log in. My homepage has, like others a log in form at the top left and after they successfully log in that is replaced with a nice big img they click on the launch the game. The C2 game is then launched in a new window. Having the script inside the head of my game html should pull the needed json...however I am not exactly comfortable poking my html page for fear of breaking it. That and java script is still on that to do list of learning.

    There is always this https://www.scirra.com/store/game-making-tools/c2-data-editor-124 I am writing Mr Gibson a pm to inquire about if this is the right tool for me and if he has any advice that will help me. And for $29.99 it will be worth paying to alive me of this headache.

  • Brought the editor long ago, it is very cool indeed. He did a lot of work. I think the capx part is even better, his use of functions and data are great.

    php file that connects to database you post/get user id (stored when user logs in) to that php file and it returns a string.

    I'm a little rusty, I actually think lennaerts multiplayer covered the basics of connecting to database retrieving and writing data. Worth a look.

    I'm sure you can save the contents of the json file as a db entry itself, thereby elimating the need for json files entirely.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Integrating a SQL Database into C2,

    Howdy, After two days of bingewatching tutorials around the net on PHP and SQL I now actually understand how they work, somewhat

    Ok so back to working on my game I now in my project file folder have a .php script and the website itself is within a webmatrix3 project. In that I have a Database that has about 20 officers listed with all there stats and info. My goal atm is to have C2 reference that Data base to populate a info card with all of each characters stats.

    So I have a DB smiler to this

    Master_Officer_List 
     
    Officer_ID    | Name | Rank        | Strength | Speed | Cost | Unlocked| 
    01               Bob        Captain        3                  2          10          True 
    02               Mark      Ensign          2                  1           5           True 
    03               Sue         Admiral       2                  1           15         False 
    04               Liz           Captain       1                  2           10         True 
    [/code:10rohfxk] 
     
    Now to make this card I have a tile set where each tile is associated with the ID value in this DB. Under that Is the Name and Rank of that person and off to the side is each stat [Strength, Speed, Cost] And It will only show the officers that are unlocked, marked True. C2 will do a For Each loop and make a new card under the first till we run out of things on the list.  
     
    Going though the SQL DB is easy enough all I need it to say is 
     
    SELECT Officer_ID,Name,Rank,Strength,Speed,Cost,Unlocked FROM Master_Officer_List WHERE Unlocked IS True; 
     
    But as always getting this integrated into C2 is proving not so easy. I know that I can upload a PHP file into C2 and using AJAX I can pull data from it bout no matter how much I look though this tutorial [url]https://www.scirra.com/tutorials/721/lennaerts-php-mysql-multiplayer-tutorial[/url] I do not understand how my PHP script should look. 
    [code:10rohfxk] 
    <?php 
    $servername = "localhost"; 
    $username = "username"; 
    $password = "password"; 
     
    $conn = Master_Officer_List ($servername, $username, $password); 
     
    if ($conn->connect_error) { 
        die("Connection failed: " . $conn->connect_error); 
    }  
    echo "Connected successfully"; 
    ?> 
    [/code:10rohfxk] 
     
    From the login portal on my homepage there is a login form for username and password and a table in my database for just that info [username, password, contact_email] and in my C2 game I have a username global variable. 
     
    Ideally I would like to have when a player creates a account that my website will make a new table titled username_Officer_List.sql that they can then wright data to as they progress and unlock/perches items. 
     
    I am makeing progress but I just am not seeing the big picture, or more how big picture is connected from all the little pictures
  • I have a straight forward question that I need explained to me in detail about AJAX

    Not including the file in my project folder how do I compose the "http// " string to get exactly what file I want?

    I have this basic folder structure in my asp.net folder using webmatrix

    localhost:7777 
    MyCoolWebsite 
         My Exported C2 Game 
              imagesfolder 
              index.html <this is my game 
         App_Data 
              config.php 
         index.html 
         MainCSS.css 
     
    <><><><><><> 
    MySQL database 
     
    PlayerData 
    MyData_Table 
    [/code:1v2vo90q] 
     
    After exporting the whole game to the C2 game folder I can not seem to connect to the config.php file. Inside C2 I have a AJAX request looking for that file only I can never seem to find what I am looking for. And not being able to do this inside C2, I have to export the whole file and clear my cookies from chrome every time I need to test a change. Understandably I am rather frustrated by this.  
     
    What do I put into the URL box? 
     
    A>"http//localhost7777:App_Data/config.php" 
    B>"../App_Data/config.php" <<i.e. do I have to go up a directory form where index.html of the game is? 
    C>"http//localhost:7777../App_Data/config.php 
     
    I know it is not any of those above because I have tried them, Please help as I have been trying at this for the better part of 6 months at trying to get player data to work. bouncing form CSV, JSON, MySQL 
     
    I just want a answer.  
     
    Thank you for your time in this.
  • This is on your own pc right?

    What are you using? XAMPP, WAMP, etc?

    Is your apache and mysql active.

    Why using ports?

    It should be http://localhost/directory structure/config.php

    Or even better tweak the hosts file and redirects etc so that

    yoursite.loc/appdata/config.php

    I like to use .loc to show it my local, then I can port it to my .com later, that way I can run development site .dev etc.

    I don't understand why the ports 7777 / you are looking for issues trying to manually configure it all up. Just install XAMPP and be done with it.

    I did this long ago, but it should still apply: tutorial this setting up XAMPP.

    Sidenote: you can't use preview and interact with database. Either have external website(to use preview), or export project to html5 on your local server(preview won't work here).

    I also think c2 runs files from the temp folder. The easiest is setting up external website, the second easiest is using xampp or something similiar and runnig local server.

  • DUTOIT Thanks, I believed that Webmatrix had its own built in settings to allow me to use ASP.Net MySQL and various other programs like a server that I just ran from within the application itself. I was wrong about that.

    I now have XAMPP 3.2.1 using Apache to set up my own network archetecher. I guess I knew that was what I should have been doing in the first place but I had believed that I was not at that point where it would have been necessary.

    I do not have a issue exporting my game to HTML5 and running that but using preview would have been nice. A few more days to get everything working like I want it and I should be able to get back to working on something game related.

    Thanks again DUTOIT for your help and that tutorial really helped a lot. This winter when there is a game to actually play I will repay everyone who helped.

  • So as a update form my last post I now have a good grasp on calling AJAX and thank you all for your support and help. I finally gave in and now have web hosting though Azure so now I can get all the data setup completed. I just have a few specific issues I need to ask.

    1 How do I "POST" using AJAX?) I know a simple question but right now I am trying to understand how this works from a how to level. I have made a sort of custom character portrait generator and am trying to save an screenshots JSON to a SQL database. I am using MS Webmatrix and have my DB from Azure linked so I hope that I can see in real time if I am indeed Posting back the JSON correctly.

    1 Unique User Profile with SQL) I have a Database called "Player Data" inside I have two tables called Player_Roster and Standard_Character_List. The first is straight forward enough that all it dose is store players username and password and will link to additional tables. The second is a little more complex as it lists all the characters and their respective stats. Each column Has things like a Name that is unique, levels of skills in TAC, SCI, and ENG along with what skills they know.

    This is more of a SQL question as to how I can auto generate a table for each player. So that when a new player creates a account on my main website I then have my database copy Standard_Character_List to be "UserName"_Character_List. But I have yet to find a resource that lays how to do that out.

    3 Calling SQL Data and fill an array) To save costs from players calling the server constantly I plan to use a C2 Array object to store relevant data the game will need to call for each action. I though need to know how to link the data in my DB to my array in C2.

    I have a active account with pluralsite.com and digitaltutors.com so if you can, you can link me a course or lesson that I should look at would be great.

    Thank you for your time,

    CrazyVulcan

  • 1 IIRC it actually depends on the server side scripting of things. You simply use the post action of the AJAX plugin on C2's side, and pass your "image" that you made as JSON previously as part of the URL you are reaching for. As mentioned in the manual, the POST method is the one selected by default for the plugin.

    2 As you said, sounds like a SQL question, as such why not searching on a dedicated forum/community for SQL ?

    3 Either manually fill the array with informations you get from your AJAX call through string manipulation (stuff like tokenat) or make it so that you saved your array asJSON on your server, and so are simply serving that JSON file and so you can use the array "Load" action.

  • Hello all its been a minute but let's get back into this. I have found a solution to how I want to handle the players unlocked items. Instead of a very large CSV file that I am pulling from my server. Which is both slow and expensive. I simply have a JSON of a C2 Dictionary that list which items are locked vs unlocked. I then after loading the dictionary use it to change a master CSV that I pull from the project folder that has everything locked as default. Seeing as right now my one faction has 125 characters one can choose from plus each having unique stats and abilities this I found is a great solution.

    Now the thing tripping me up at the moment is more basic to C2. In my menu I have six instances of my officers I can choose from. Also instances of text items for their name, various stats and abilities. This is something that I have always had a time of wrapping in my head. How does one translate how one object functions by using a different object?

    I have a "For each Row in Column" Loop with the Compaire Two Items "CSVOfficer.At("Unlocked",CSVOfficer.CurRow). I also have a Pick instance just selecting instance 0 of one of my six sprites that show the portrait of the officer in question. I then want to change the frame of that sprite to equal the row (which is indexed numerically) of my CSV.

    That works all well and good but now I am attempting to do the second sprite (the other five as well) Where it is the same only i Pick instance 1 of my sprite. But without knowing how to increment to the next option those five sprites end up being the same as Sprite number 0.

    I've tried adding the sprites IID number to the option when setting the frame but that will not work since it is possible for the next row to be false so if they were on row 3 and I add one it then would display row 4 but if row 4 was false then that is not right.

    And that is not even taking into account flipping through pages of all the officers.

    Thank you for your time,

    CrazyVulcan

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