How do I set this up correctly

0 favourites
  • 12 posts
From the Asset Store
A whole set you need to create a gorgeous winter 2d game
  • Okay so I'm trying a different type of game where users will work together with others who use the app, while only playing alone actually.

    So let me try to explain it,

    A single person will click a button on their screen to add points. Once the person is ready to cash in those points, a plugin (after research I assume I'd be using something like AJAX or XML) will post the players cashed in points to a number stored which gathers all points collected by everyone else who has used the app. Basically making it a team effort to build this number up as high as possible.

    So, is this possible? I would hope it would be, but then I think of all the errors that could come out of it, like people posting at the same time and maybe messing up the total number, I'm not sure or the system would wait until the first person's number is added before the next, it's very complicated which therefore is difficult for me to explain.

    In summary, I am trying to figure out if it is possible to have a number stored somewhere (on a file of course that would be linked to a URL), that Construct 2 can access that number and add to it the points the player is cashing in, and making the total now higher, and everyone who contributed can now see the new point total.

    I am stumped and didn't seem to find a tutorial that explained my situation, probably because my situation is rather complicated, any help is appreciated

  • HI Yes that's certainly possible. If you can't find a tutorial I'll see if I can put something together for you.

  • OK, what I would do is this:

    1) set up a hosted database somewhere that will track the points.

    2) whenever a player cashes in some points you want the app to make an AJAX call to a url linked to the database, which will create a record to store those points.

    3) during play each player's app makes regular AJAX calls to a similar url which triggers a database query to show the total of all of those records which were created in step 2.

  • Thanks for the reply hundredfold, so from what your saying is that I need to set up a mysql database right? I tried last night to set it up where AJAX calls a number from a php file which is located with the game's files on my webhost, but no avail. So I will try what you said and see if it works! I'm going to get started on it now trying to set it up, but I'm a beginner at mysql databases so I'm still trying to familiarize myself with the coding, if you have any example pages and coding I could work off of I would greatly appreciate it, if not I will begin the quest of trying myself

    Thank you!

  • Hi Yes php/mysql will certainly do the job. There's tons of tutorials around online for those and places you can get them hosted for free too. Also, if you're new to mysql you might find phpmyadmin useful as it gives an interface a little more like MS Access. You can get this set up in your localhost environment for testing offline without a host provider by using XAMPP.

    Focus on how to:

    • set up tables (to hold the records)
    • insert records (to capture each score)
    • use SUM queries with SQL

    Let me know if you don't get it working using what's already available and I'll see if I can find some time to help you a little more with the detail.

  • Thanks so much for the feedback and tips hundredfold, I've managed to get somewhere but not to the finish line yet unfortunately. Once I get this down I'm pretty sure I'll have Mysql all figured out

    I have some code already that I've put together based off of what I've read on tutorials around the web. (At point you might notice something I inputted incorrectly I'd appreciate it if you'd let me know )

    Code #1: The creation of the table that stores all the scores

    CREATE TABLE ATotalPoints (
    total_points DECIMAL(12,2) NOT NULL DEFAULT 0.00
    ) ENGINE = MYISAM DEFAULT CHARSET = utf8;[/code:2v4mg3v0]
    
    *I have a weird feeling that the line with "total_points DECIMAL..." is wrongly coded but I'm not entirely sure, based off of the knowledge I've received. And actually the rest of the creation code I'm skeptical about, but when I put that code in the myphpadmin, it successfully created a table, below is a picture of what the results :O
    
    [img="http://i62.tinypic.com/jqkihk.png"]
    
    So then I'm assuming the table creation process is complete, I went to my webhost to create a php file that posts the score that the player posts, which the code is below (for security I blocked out my server information  )
    
    [code:2v4mg3v0]<?php
    $score = $_GET['score']; 
    $con = mysql_connect("*****","*******","******");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
      
      mysql_select_db("ATotalPoints", $con);
      
      mysql_query("INSERT INTO ATotalPoints (score) VALUES ($score)");
    
    mysql_close($con);
    ?>[/code:2v4mg3v0]
    
    So then I saved  the php and placed it with my game files on my webhost, then went to construct and where the player can submit the score, I inputted the request for AJAX to use the php, below is what it looks like-
    
    [img="http://i61.tinypic.com/2l28a1.png"]
    
    Then from what I believe, I would then be able to export my game to my webhost, go the point where I'd post the score. I didn't get any errors from the game about the request for posting, but then once I went to my table to check if the score was posted, it says the same thing as the beginning, or would it even show me there? I know I still have the process of requesting the sum score of everyone combined, but right now I'm trying to figure out on just the posting part... HELP
  • Hi Cgimler well done you're doing great.

    Your current block could be caused by your host being cautious about cross-domain AJAX calls.

    If you add the following line to the top of your php file it could well sort that for you:

    (inside the php tags)

    header('Access-Control-Allow-Origin: *');

    Also, you might want to eventually upgrade the table to include some other fields if you'll ever want to see where specific scores are coming from, or if you want more than one group to play without affecting each other's scores.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks again hundredfold I add that to my php file just to be safe and see if it works! I did plan on making different groups but I didn't think I would put the same scores in the same table, rather make two separate tables, but that might be a waste a time, I guess I'll just figure it out on the way through it all haha!

    At this point I'm gonna try to continue figuring this out as I go along, I do appreciate all your help so far, if I have any other questions I'll give you a hollar, but hopefully I won't have to

  • So actually the php file I made isn't connecting because of a code error ) to it telling me this error...

    <br />
    <b>Fatal error</b>:  Call to undefined function mysql_connect() on line <b>4</b><br />[/code:wef7s8d0]
    
    so there might be issues with my webhost, so now, I'm going to try getting it to work with XXAMP on my local computer... I guess :/
  • Hi - get all your connection stuff working on your host before trying the AJAX connection.

    You should be able to test the scripts by just running the url directly in the browser.

    Normally a host will provide example connection scripts for you.

    It'll be the same with localhost - you'll still need to connect to the database.

  • Hi Cgimler - have you had any joy with your database connection?

  • Hi hundredfold ! thanks for checking up on me! I'm finally back from work, so I'm going to try to work on it again, I was realizing that the webhost I was using wasn't going to allow me to edit certain php files so the connection will work, so I'm going to try getting it to work on my local computer, and we will see how it goes, I'll let you know, thanks

    hopefully everything will go smooth as I think I've come to figure out the basics, but I might need some help here soon!

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