A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [RESOLVED] [AS2] Argh, just ONE VARIABLE SAVE!?

  1. #1
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167

    resolved [RESOLVED] [AS2] Argh, just ONE VARIABLE SAVE!?

    Seriously, saving is out to kill me.

    Sometimes it works, and then when I do the exact same thing another time it decides not to and I'm extremely frustrated. Let me break down this extremely, extremely simple setup:

    Basically for a simple game I'm making, I just want to store three (I know I said 'one variable', but it won't even work with one...) things about the top highscore player. Name, Score, and Message. SIMPLE. So, I start by loading it:


    Load the Three Existing Variables
    PHP Code:
    myData = new LoadVars();
    myData.onLoad = function() {
        
    champName.text myData.Name;
        
    champScore.text myData.Score;
        
    champMsg.text myData.Msg;
        
        
    topScore myData.Score;
        
    };
    myData.load("save.txt?"+Math.ceil(random(9999))); 

    Great, it works fine when I test it and everything. You play the game, you eventually lose, and then it does a highscore check. If you get the highscore, you are asked for you name and a simple message.

    When you click submit, the function saveScore() is called and looks like so:

    Send Everything to PHP
    PHP Code:
    saveScore = function () {
        
    myData.Name topName;
        
    myData.Score topScore;
        
    myData.Msg topMsg;
        
        
    myData.sendAndLoad("save.php",myData,"POST");
        
        
    _root.gotoAndStop(1);
    }; 
    Any trace done will return the proper value, including trace(myData) will return all three updated variables (Name, Score, Msg). Then it sends it to the PHP for saving.

    The PHP is like so:

    Write to Text File
    PHP Code:
    <?php 
    $saveName 
    $_POST['Name']; 
    $saveScore $_POST['Score'];
    $saveMsg $_POST['Msg'];


    $toSave "Name=".$saveName."&Score=".$saveScore."&Msg=".$saveMsg

    $myfile 
    fopen("save.txt","w"); 
    fwrite($myfile,$toSave); 
    fclose($myfile); 
    ?>

    Grab each, store it all in one variable and write it to the text file.


    SIMPLE!?

    I don't know, it just won't write to the text file! Someone, please save me from my misery so I can continue on with my project.
    Last edited by Osteel; 11-20-2009 at 05:10 PM.

  2. #2
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    838
    Your Flash part looks right to me, I haven't done AS2 stuff in a while but it doesn't look obviously wrong.

    I'm not a PHP wiz, but I would try debugging the PHP script. Try making the PHP display the variables you're looking for.

    PHP Code:
    print "Name=".$saveName."&Score=".$saveScore."&Msg=".$saveMsg
    Or however you do that. And then I would try testing the PHP with GET variables to see if it even writes what you expect to the text file. Like...

    PHP Code:
    saveGame.php?Name=Joe&Score=1234&Msg=Good 
    If your script works that way, you can determine it's Flash that's causing the problem.

  3. #3
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    Also make sure you actually have write permissions to the directory.....chmod the directory to 777
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  4. #4
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Thanks for the help!

    So I'm going to try those two debugging techniques and see if its the PHP or Flash. Also, I've set the permissions via the option on FTP site I'm using ... but maybe I should do it in PHP.

    Time to go test.


    --------------------

    Edit:

    Sigh. I've set the permissions on all the files and the directory to allow everything and anything. I've even tried the following, as suggested by someone else on the forum:

    PHP Code:
    <pre>
    <? var_dump($_POST); ?>
    </pre>
    Which displays through PHP the exact variables and values of each variable that PHP needs to write in the text file for the Name, Score and Message.

    And it still won't write. ARRRGH.
    Last edited by Osteel; 11-20-2009 at 08:20 PM.

  5. #5
    Senior Member Orkahm52's Avatar
    Join Date
    Jan 2006
    Location
    Perth, Australia
    Posts
    335
    As far as I can see both codes are okay so all I can suggest is basic debug stuff.

    Have you tried just writing a string to the file?As in, fwrite("testing", "w");

    If that doesn't work then you know it's either the permissions or the site your using has a really old version of PHP.

  6. #6
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Ah.

    Well, a little bit of good news. I made a simple PHP file on the website itself with the following code:

    PHP Code:
    <?php 
    $myfile 
    fopen("test.txt","w"); 
    fwrite($myfile,"testing"); 
    fclose($myfile); 
    ?>
    And it does write the word testing to the text file test.txt while on the website. So that rids the problem of PHP not being supported.

  7. #7
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167

    Embarrassed!

    Okay, so I'm a little embarrassed ... it turns out that I wasn't resetting the permissions on the SWF file every time I uploaded it to the FTP, and was only doing so to the PHP/Text file.

    So it works.

    I'm sorry for wasting everyone's time, but appreciate the willingness to help me out. Thanks.

  8. #8
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    Code:
    <?php
    $saveName = $_REQUEST['Name'];
    $saveScore = $_REQUEST['Score'];
    $saveMsg = $_REQUEST['Msg'];
    
    
    $toSave = "Name=$saveName&Score=$saveScore&Msg=$saveMsg";
    
    echo $toSave;
    
    $myfile = fopen("save.txt","w");
    
    echo $myfile;
    
    fwrite($myfile,$toSave);
    fclose($myfile);
    ?>
    the above code worked when I tried it in wamp, locally.
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

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