Not sure I FULLY understand what exactly you are trying to accomplish here... BUT...
You sound like a very intelligent person, so reading between the lines and manipulating what you need to get the results you are after shouldn't be too tough.
If you are looking for the ability to save things locally on someone's PC, using flash... try shared objects.
HERE is a short tutorial with coding.
And This One has more detail and uses cookies, which are .txt files yes?
This One uses SQL and php to store data such as player position, inventory, etc. WIth good instructions, shouldn't be too hard to tweak.
Finally this one is your basic highscore list, which I have used many time (after getting to work properly with php4+) Again, using INSERT and POST/GET to store info to a .sco file (can be renamed to .txt if needed)
if you look at the last one, download the zip file and replace the scores.php with this:
Code:
<?php
error_reporting(E_ALL);
function getPlayerScore() {
// get the winscore variable from the query string - make sure it's an integer
$score = (isset($_GET['winscore'])) ? (int) $_GET['winscore'] : 0;
// get the winname variable removing leading and trailing whitespace and the | character
$name = (isset($_GET['winname'])) ? trim(str_replace('|', ' ', $_GET['winname'])) : '';
// high score records are stored as score|name
return $score . '|' . $name;
}
function getAction() {
// an array containing the possible actions
$actions = array('VIEW', 'INSERT', 'CLEAR');
$action = (isset($_GET['action'])) ? trim(strtoupper($_GET['action'])) : 'VIEW';
// make sure the action is valid
if (!in_array($action, $actions)) {
$action = 'VIEW';
}
return $action;
}
function createFile($filename) {
// if a the file doesn't exist try to create it
if (!file_exists($filename)) {
$fp = fopen($filename, 'w');
if (!$fp) {
// the file couldn't be created
return false;
}
fclose($fp);
}
// if we got here the file is ok
return true;
}
function writeFlash($name, $value, $exit = false) {
// write out a variable name and value to be read by flash
echo '&' . $name . '=' . urlencode($value) . '&';
// if $exit has been set stop the script right here
if ($exit) {
exit();
}
}
function writeFile($filename, $str) {
// write a string to a file
$fp = fopen($filename, 'w');
fwrite($fp, $str);
fclose($fp);
}
function process() {
// define the location of the highscores file
$scoreFile = 'scores/highscores.sco';
// and define the number of results
$scoreSize = 10;
// get the action so we know what to do!
$action = getAction();
// try to create the highscores file if it doesn't exist already
if (!createFile($scoreFile)) {
// if the file didn't exist and can't be created return an error message
writeFlash('status', 'There was an error accessing the highscores list', true);
}
if ($action == 'CLEAR') {
// clear the scores file
writeFile($scoreFile, '');
// and send a message back to flash
writeFlash('status', 'The list has been cleared', true);
}
// read the scores in the file into an array
$fileScores = array_map('trim', file($scoreFile));
if ($action == 'INSERT') {
// if we've got a score to add to the end of it
$fileScores[] = getPlayerScore();
}
// an create a couple of empty arrays that we'll use for sorting our data
$scores = array();
$names = array();
foreach ($fileScores as $scoreData) {
// put the scores and names into the 2 arrays
list($scores[], $names[]) = explode('|', $scoreData);
}
// sort it! get $fileScores sorted so the scores are in descending order
array_multisort($scores, SORT_DESC, $names, SORT_ASC, $fileScores);
// if we have too many scores trim off the lowest ones
array_splice($fileScores, $scoreSize, count($fileScores) - $scoreSize);
// write the content of the fileScores array into the file (with each score|name separated by a newline)
writeFile($scoreFile, implode("\n", $fileScores));
// loop through the scores
foreach ($fileScores as $key => $scoreData) {
$tmp = explode('|', $scoreData);
// and write out a list of variables score0, name0, score1, name1 etc...
writeFlash('score' . $key, $tmp[0]);
writeFlash('name' . $key, $tmp[1]);
}
writeFlash('status', 'things are fine');
}
process();
?>
Of course, all of these are meant for games, but again, easily tweaked for your needs... that is, IF I understood what you wanted to do.
Bookmarks