Advanced C2 - Building a Online Browser Game With C2

Get help using Construct 2

Post » Thu May 07, 2015 7:59 am

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 ;)
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
61
S
16
G
9
Posts: 1,429
Reputation: 12,484

Post » Thu May 07, 2015 10:47 pm

DUTOIT wrote: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.
"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
6
S
2
Posts: 113
Reputation: 1,220

Post » Thu May 07, 2015 11:34 pm

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.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
61
S
16
G
9
Posts: 1,429
Reputation: 12,484

Post » Fri May 29, 2015 11:18 pm

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 :lol:

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
Code: Select all
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


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 https://www.scirra.com/tutorials/721/lennaerts-php-mysql-multiplayer-tutorial I do not understand how my PHP script should look.
Code: Select all
<?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";
?>


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
"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
6
S
2
Posts: 113
Reputation: 1,220

Post » Mon Jun 01, 2015 1:03 am

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

Code: Select all
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


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.
"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
6
S
2
Posts: 113
Reputation: 1,220

Post » Mon Jun 01, 2015 7:31 am

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.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
61
S
16
G
9
Posts: 1,429
Reputation: 12,484

Post » Thu Jun 04, 2015 9:54 pm

@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.
"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
6
S
2
Posts: 113
Reputation: 1,220

Post » Wed Jul 15, 2015 4:14 am

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
"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
6
S
2
Posts: 113
Reputation: 1,220

Post » Wed Jul 15, 2015 9:43 am

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.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
253
S
86
G
42
Posts: 7,037
Reputation: 59,189

Post » Wed Sep 16, 2015 6:24 pm

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
"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
6
S
2
Posts: 113
Reputation: 1,220

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Laurent and 3 guests