A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: highscore table[help]

  1. #1
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067

    highscore table[help]

    Hey guys.

    I know this is strictly a php question but being as im trying to make my own highscore table from scratch for a game i thought it would be ok to post here, besides i know ill get a quicker response here.

    <?
    $name=$_POST['name'];
    $score=$_POST['score'];
    IF ($score>"900")
    {
    echo "Your name is ". $name .

    ".<br>";
    echo "You scored ". $score .".<br>";
    }
    ELSE
    {
    echo "Sorry that is not good

    enough"".<br>";
    }
    ?>

    Ive got this in my php file.

    It keeps saying line 11 has a problem but i cant see it myself. The passing of the variables from the flash file to the php doc work fine and it works fine if i dont have the else statement, so it must be that, but after checking through other peoples code it doesnt seem to be wrong, can someone see whats wrong.

    Thanks in advance.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  2. #2
    Razor
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    721
    In my years of php programming I've never seen a full capital ELSE I might be wrong but try to make it lower case along with your IF so IF = if and ELSE = else because the else line is where your getting the error.

    This answer is pure theory as I have never tested using capitals so I might be wrong about this.

    Another thing might be the quotes around 900 that could be causing it to check in order which ascii value is bigger and but you want it to check the actual numerical value, try removing those. And just to clean it up take out the odd blank lines and gaps.

    So something like this is what im thinking:
    Code:
    <?
       $name=$_POST['name'];
       $score=$_POST['score'];
       if($score > 900)
       {
          echo "Your name is ". $name . ".<br>";
          echo "You scored ". $score .".<br>";
       }else{
          echo "Sorry that is not good enough"".<br>";
       }
    ?>

  3. #3
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067
    Thanks for the effort but it doesnt work.

    I actually did this from a tutorial so i dont understand why it doesnt work.

    Thanks anyway.

    ps. could it be a problem from the fla document, although i dont see how that is possible being as if i dont have the else statement it works, what the hell is wrong with this bloody thing.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  4. #4
    Razor
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    721
    Before the if do an echo on the variables see what there values are. Because if score is NULL that could be causing the error.

  5. #5
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    php isn't case sensitive so capitalisation won't matter:

    PHP Code:
    <?
       $name=$_POST['name'];
       $score=$_POST['score'];
       if($score > 900)
       {
          echo "Your name is $name.<br>";
          echo "You scored $score.<br>";
       }else{
          echo "Sorry that is not good enough.<br>";
       }
    ?>
    Last edited by token 3; 05-29-2005 at 10:07 AM.

  6. #6
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067
    score =1000, which it should because that is set in flash.

    What else could be causing the problem, ive probably done something stupid being as ive only been doing php for a couple of days.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  7. #7
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    ~yarr your problem was a double quote
    enough"".<br>";

    ^^see code above

  8. #8
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067
    God damn crap tutorial, i even pasted the code from that in to see if that worked and it didnt, i hate php already.

    Thanks for help guys, ill remember to check code thoroughly in future.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  9. #9
    Razor
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    721
    Originally posted by token 3
    ~yarr your problem was a double quote
    enough"".<br>";

    ^^see code above
    Haha lol nice token.

    lol dont worry about it Kakihara I alway used to do that and spend so long looking for the error :P

  10. #10
    Flash hates me. crashlanding's Avatar
    Join Date
    Nov 2003
    Location
    UK
    Posts
    439
    Originally posted by Kakihara
    i hate php already.
    Join the club
    "wen i found my gerbil dead my other gerbil was eating it i just cried and screamed"
    http://www.livescripts.net

    --------------------------------------------------------------------------------
    Last edited by some moderator : Today at 9:01 PM.

  11. #11
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067
    Lol.

    Ive got another question.

    Ive managed to get flash to send a variable to a php script and get the php script to save that variable into a txt file if it is bigger than the text files variable current value, but it adds it to the end of the original value, i know its the "a" that does this but how do i make it overwrite the current value of the variable in the text file or even just remove the current variable so that the text file is empty.

    heres the code:

    <php>
    <?


    $score1=$_POST['highscore'];

    $playerscore=$_POST['entry'];

    if($playerscore>$score1)
    {
    $score1=$playerscore;
    $file="myscores.txt";
    $open=fopen($file);

    if($open){
    fwrite($open,$score1);
    fclose($open);
    }
    }
    echo $score1;

    ?>
    </php>


    Thanks in advance for any help.

    ps. this is my last phph question in this forum i promise.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  12. #12
    Razor
    Join Date
    Aug 2002
    Location
    Canada
    Posts
    721
    you could delete it and then recreate it.

  13. #13
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067
    Yeh i did think of that but being as im going to take the file that one step further and have many variables inside it i only really want to update the variable, so that the rest stay the same, is there a way of just overwriting a specific variable.

    Thanks.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  14. #14
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    have a look at this editor (i'm sure there are better ones) it has a php highlighter which might help to pin point these types of errors;
    http://www.crimsoneditor.com
    ps: one good way to write stuff to a file in one step is to use the serialize()/unserialize() commands. they will write an entire array out to a file.
    Last edited by BlinkOk; 05-30-2005 at 06:32 AM.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  15. #15
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067
    Thanks for the link Blinkok, ill check it out.

    I would really like an easier way though, isnt there a command like 'fwrite' that can do this , maybe 'foverwrite' or something, must be an easy way of updating a variable other than deleting the entire txt file, because i only want to update one variable at a time and so i dont really want to delete all the other variables.

    Thanks.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  16. #16
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    you still might wanna consider it coz remember if the score qualifies then you will be re-arranging the entire table. alternatively you might consider using a database and sql.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  17. #17
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067
    I was just going to have 10 variables, score1, score2 etc... and some if statements saying if playerscore>score1 then score1=playerscore and score2=score1, score2=score3 etc...

    I know this is a bad way of doing it being if i want 100 scores but i can use the idea for a few other things like holding what level someone was at when they died, so then they can restart from the same level.

    I dont really want to move onto mySQL yet as i want to get used to the basics of php first.

    Is there somewhere that lists all the php commands like echo and fwrite, a bit like the flash help file does, then i can just check it out myself.

    Thanks.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  18. #18
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    I dont really want to move onto mySQL yet as i want to get used to the basics of php first.
    Just dive straight in mate!, it's not too difficult; it will certainly make your life a lot easier, rather than reading and writing to files.

  19. #19
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067
    Yeh i may just do that, it will definetely make making big highscore tables and things a lot easier.

    Ive actually found a solution to my problem, i use the unlink() function to delte the txt file and then just create a new one everytime, obviously i hold all the variables and there values so they can all be placed in the new txt file. I figure if i can now get it to save the txt file to the users computer and read from it, i should be able to have save games.

    Anyway thanks for all the help guys.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  20. #20
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center