Game replay?

0 favourites
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • MySQL would sure make things alot easier ;-)

  • Yeah if i could only figure out how to set one up ;D

  • So, the PHP now is working?

    I would grant you access to one of my DB, but due to security restrictions of my provider, i can not....sorry <img src="smileys/smiley19.gif" border="0" align="middle" />

  • Don't Worry I figured it out.

    "So, the PHP now is working?" <- Im not sure, I tested it but I wasn't sure how to apply the data to the sprite, And if I needed 3 logs, one for x, one for y, and one for angle. In the PHP you kindly provided there was only one log, not sure if i need more?

    Oops only just saw your last message.

    Sorry forgot to give link to CAPX,

    Here it is,

    dl.dropbox.com/u/51270524/Replay.capx

  • Weishaupt, Did you see the capx.

    When I said "Don't Worry I figured it out." I meant the mysql part <img src="smileys/smiley1.gif" border="0" align="middle" />

    I also managed to do the login system, Without mySql, if you wish to see that i'll upload it soon :)

  • First - no, you need only ONE log, since all x,y,and z is stored there...

    So if you can retreive the LOG for one named user, you should be able to play it back to him...

    And Second, if a log for any named user exists on you server, you should be able to load this. maybe you want to generate a second CSV file, that hold all usernames that have been saved, so you can generate a pick list

    Sorry, I am also working on the rotary challenge ;-)

  • Weishaupt

    Yeah im gonna start work on the rotary comp as soon as i finish this :)

    Few more questions if its not too much trouble

    Sending the data -

    Curretly im sending it like this : "http://blablabla.com/post.php?name=BlaBlaBla&log="&int(tokenat(state,0,","))"

    But " log="&int(tokenat(state,0,",")) is only the x.. so how do i send the rest?

    Playing it back -

    How am i supposed to do this?

    sprite.SetX(Ajax.LastData)

    sprite.SetY(Ajax.LastData)

    sprite.SetAngle(Ajax.LastData)

    About the naming thing im obsessed with how do i do this -

    were sending a username: [name] in the PHP script, But say I have a scoreboard, how do i then search for the same name?

    Would something like this work?

    <?php

    $username = $HTTP_GET_VARS[name];

    $log = $HTTP_GET_VARS[log];

    $mystring = $HTTP_GET_VARS[CurrentUser];

    $findme   = $mystring;

    $pos = strpos($mystring, $findme);

    // Note our use of ===. Simply == would not work as expected

    // because the position of 'a' was the 0th (first) character.

    if ($pos === false) {

        echo "The string '$findme' was not found in the string '$mystring'";

    } else {

        echo "The string '$findme' was found in the string '$mystring'";

        echo " and exists at position $pos";

    }

    ?>

    But then how would i use this string to display the data of the current user?

  • why dont you send the log only once at the end of the race. at this time it shoule hold all the data?

  • Weishaupt

    Because the log is not one object is it?

    int(tokenat(State,0,","))

    int(tokenat(State,1,","))

    int(tokenat(State,2,","))

    we have to log the data 3 times?

    or am i supposed to send something else?

  • Also for your "registering" process there a mysql base would come in handy.

    You'd make a MYSQL request SELECT to take only $username from the base.

    This is why earlier I said you should learn/find documentation for it, because it is a full topic that is beyond the scope of C2's forum as it is highly depending on how you setted up your server.

    But this is what you're looking for for the leaderboard/registering, etc...

    The server side PHP/Mysql deals with storing/providing/processing datas of all your clients, your client deals with retrieving specific datas for a user and providing new ones (replays).

  • Kyatric, I looked into mySql earlier today.

    My server was taking too long to download the package so i will try again later. I understand the mysql part quite well. There are lots of example's out there for setting it up.

    The table would look like this:

    CREATE TABLE `myDB`.`usersystem` (

    `userid` INT NOT NULL AUTO_INCREMENT ,

    `username` VARCHAR( 50 ) NOT NULL ,

    `password` VARCHAR( 32 ) NOT NULL ,

    `email` VARCHAR( 50 ) NOT NULL ,

    PRIMARY KEY ( `userid` )

    )

    then the php like this: <?php

    session_start();

    mysql_connect("localhost", "username of your database", "password of database");

    mysql_select_db("myDB");

    function user_login ($username, $password)

    {

    //take the username and prevent SQL injections

    $username = mysql_real_escape_string($username);

    //begin the query

    $sql = mysql_query("SELECT * FROM usersystem WHERE username = '".$username."' AND password = '".$password."' LIMIT 1");

    //check to see how many rows were returned

    $rows = mysql_num_rows($sql);

    if ($rows<=0 )

    {

    echo "Incorrect username/password";

    }

    else

    {

    //have them logged in

    $_SESSION['username'] = $username;

    }

    }

    ?>

    The thing i don't quite understand is then how do i find the users name from the php that saves the replay?

  • It's one of the parameter sent in the url you put in your ajax request.

    Send ajax request: "http://myurl.ext/myScript.php?myParam1=value&myParam2=value?myParam3=value" etc...

    You set "myParamX" as you wish, it is your call, to a script that you made and will retrieve X params from its url in the $HTTP_GET_VARS array.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Kyatric ,

    Yeah I know im sending the [name] and log. The problem is finding that name, Im probably really confusing people now.

    Essentially I want to be able to show the top 100 people's replays on the scoreboard, And the players own replays.

    But thats not important right now.

    I need to be able to search through the CSV for a [name] then display the specific data from that [name]

  • You should then check PHP references and check the strings functions.

    The language has standard functions (in C2 that's system expressions ^^).

    str_split can turn your string ot an array.

    strpos will return the index of the first character of the search string or a default value if it is not found.

    Etc... ^^

  • GingerBatMan, Kyatric

    Yeah I also had a look at strpos function

    Came up with this, But it doesn't feel right:

    <?php

    // read variables from POST data.

    $username = $HTTP_GET_VARS[name]; <-- DEFINE THE USER??

    $log = $HTTP_GET_VARS[log]; // <-- MODIFY THIS TO SEND THE REPLAY??

    $mystring = $HTTP_GET_VARS[CurrentUser];

    $pos = strpos($mystring, $username);

    // verify the username is set and not empty

    if (!isset($username) || $username == "") {

        echo "failure";

        exit;

    }

    // verify the log is set and a number

    if (!isset($log) || $log == "") {

        echo "failure";

        exit;

    }

    if ($pos === false) {

        echo "The string '$username' was not found in the string '$mystring'";

    } else {

        echo "The string '$username' was found in the string '$mystring'";

        echo " and exists at position $pos";

    }

    ?>

    Then the read.php

    <?php

    /** Return a list of top logs. */

    // read variables from GET data

    $num_logs = $HTTP_GET_VARS[num_logs];

    // read each line in logs.csv as a string into an array

    $logs = file("logs.csv");

    // define a comparator to sort items by log

    function compare($s1, $s2) {

        // split the strings by their delimiter

        $a1 = explode("#", $s1);

        $a2 = explode("#", $s2);

        // compare the logs

        return $a2[1] - $a1[1];

    }

    // sort the array of logs

    usort($logs, "compare");

    // output the requested number of top logs

    for ($i = 0; $i < $num_logs && $i < count($logs); $i++) {

        echo $logs[$i];

    }

    ?>

    Im not sure what im supposed to do the the read php to return the replay you need when you want it <img src="smileys/smiley5.gif" border="0" align="middle" />

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