|
-
the cheesy child
PHP store muliple variable in txt
Hi... I'm now pretty familiar to how PHP works with flash.
I know how to send variables from flash to PHP, how to write a variable from PHP to a txt file and then how to get variables from a text file to flash.
Yay! It all works good!!!
not quite.
I'm trying to make a highscore game. each level has its own one highscore as well as the name of the person on top.
anyway to get stuff from flash to PHP is simple I know all that.
fwrite($file, "score=".$score);
yeah uh, how do I make it write 2 things without them intefering?
is it like:
fwrite($file, "score=".$score);
fwrite($file, "name=".$name);
well thanks to anybody who will help.
-
FK'n_dog
$vars=$name.":".$score; // : is a delimiter, so $vars=bounceboy:99999
fwrite($file, $vars);
when you retrieve the data in Flash, split the values by the delimiter
-
the cheesy child
-
A delimiter is used to specify the boundarys
e.g
this-is-example | delimiter = " - "
this:is:example | delimiter = " :"
this,is,example | delimiter = " , "
Freelance: AS2, AS3, PHP, MySQL, JavaScript
Skype: hunty93
-
the cheesy child
how do I split the variables by the delimiter?
listen... Is there a way to make arrays in PHP?
-
to split....use explode
PHP Code:
<?php
$q = "hello,i,am,hunty";
$arr = explode(',',$q);
$i = 0;
while ($i < count($arr)) {
echo $arr[$i];
$i++;
}
?>
Freelance: AS2, AS3, PHP, MySQL, JavaScript
Skype: hunty93
-
the cheesy child
Hey thatnk you but I meant in flash when i load the variables.
but who cares, I got it to work easy like this:
<?php
$score = $_POST[score];
$name = $_POST[name];
$myfile = fopen("score1.txt","r");
$fp = fwrite($myfile, "&score=".$score);
$fp = fwrite($myfile, "&name=".$name);
fclose($myfile);
print "&response=".$text;
?>
It worked... so I did this to all 6 of the data writers.
I also re-uploaded the txt files and now they don't work.
I submit highscores and It won't change them a bit... its like my PHP script isn't working now that there's 6 that are similar...?
or is it something to do with the code i used in flash:
saver = new LoadVars();
reader = new LoadVars();
desnum = _root.design;
function submit(){
saver.score = _root.clicks;
saver.name = username;
saver.sendAndLoad("score/make"+desnum+".php",reader,"POST");
}
reader.onLoad = function(suc){
if(suc){
prevFrame();
}
}
Somebody please help me... thank you!
-
im quite tired ,, but just made a example of receiving vars in flash
Code:
on (release) {
desnum = _root.design;
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
var my_str:String = this.infoA;
var my_array:Array = my_str.split(",");
highscore = "name: "+my_array[0]+" score: "+my_array[1];
trace(highscore);
} else {
result_ta.text = "Error connecting to server.";
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.score = _root.clicks;
send_lv.name = username;
send_lv.sendAndLoad("score/make"+desnum+".php", result_lv, "GET");
}
and in php make it parse the array like this:
PHP Code:
echo "&infoA=" . $name . "," . $score . "&";
not tested but...it should all work
hope this is anyhelp at all..if not... specify in detail what you want...and ill make it my self.
Freelance: AS2, AS3, PHP, MySQL, JavaScript
Skype: hunty93
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|