Game replay?

Get help using Construct 2

Post » Fri Jan 06, 2012 9:39 pm

@Yann no I didn't. Should that theoretically make it easier to send data and then retrieve it?
B
8
S
2
G
4
Posts: 55
Reputation: 2,555

Post » Fri Jan 06, 2012 9:40 pm

[QUOTE=Yann] I don't know if you noticed but the 'log' variable... is in CSV (Coma Separated Value)... Just saying :D[/QUOTE]

I did, thats why I said he has to change the delimiters in his PHP
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Fri Jan 06, 2012 9:43 pm

@GingerBatMan
Not at all... Just saying :D
A string is a string there's no spacial treatment if a string as some coma or not.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Jan 07, 2012 4:41 pm

@Weishaupt, Any news? :)
B
8
S
2
G
4
Posts: 55
Reputation: 2,555

Post » Sat Jan 07, 2012 5:24 pm

Sorry GingerBatMan - I had not had a chance to look at it today :-(
No bad feelings please - there are days I am just not able to "work"
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Sat Jan 07, 2012 5:47 pm

@Weishaupt, No worries mate. Whenever your feeling good.
B
8
S
2
G
4
Posts: 55
Reputation: 2,555

Post » Sun Jan 08, 2012 10:36 am

GingerBatMan:

Try the following PHPs:

<?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??

// 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;
}

// format the username and log as a comma delimited row
$entry = $username . "#" . $log . "\n";

// append entry to the log file
if (!file_put_contents("logs.csv", $entry, FILE_APPEND)) {
    echo "failure"; // failed to write to file
    exit;
}

echo "success";
?>


...and...



<?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];
}
?>
Weishaupt2012-01-08 10:37:43
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Sun Jan 08, 2012 3:14 pm

@Weishaupt, Thanks for this, I understand it quite well.

Take a look at the capx, I cannot really figure out how to then play the downloaded replay.. There are a few questions within the capx if you wouldn't mind answering if you can.

Also Is it possible to display a list depending on the username?

- So for example if a user searched 'Jhon' then it would display a a list of 'Jhon's replays?

- Or something like corresponding the replay with the scoreboard?
     -> for example the top 100 people in the world, you can view there replay?

The second one kinda answers itself if the first one is possible. Because you could search for the name depending on the position of the user.

B
8
S
2
G
4
Posts: 55
Reputation: 2,555

Post » Sun Jan 08, 2012 3:35 pm

first of all, does saving and loading now work?

....and where is the CAPX for me to look at?! Weishaupt2012-01-08 15:36:19
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Sun Jan 08, 2012 3:41 pm

for that kind of stuff, I think it would be better to store the log in database along with user name and scores.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: djcrazypants, marekmk and 5 guests