4 Replies Latest reply on Aug 29, 2006 7:09 AM by lsands

    Problems with seeing variables pulled out of database


      I'm having problems with the following code, it pulls player names out of a database to be added to a list later, however outside of the statement where the player name are being assigned they are not recognised i.e. the bits where i'm writing [CODE]trace('1this is player 1s name'+ player1Name);[/CODE] etc. There are also 4 variables to do with a key count, and as far as I can see i'm treating them the same, declaring them at the top, assigning them values and when i print them out later they're fine, the only difference I can see is the type of variable these things are.

      I've initialised the variables at the top, i've tried making them global, doing [CODE]var player1Name: String;[/CODE], it seems such an easy problem but I can't figure it out....

      Here's the relevant part of the code:

      var stage3player1keyCount=0;
      var stage3player2keyCount=0;
      var stage3player3keyCount=0;
      var stage3player4keyCount=0;

      var player1Name="";
      var player2Name="";
      var player3Name="";
      var player4Name="";

      //this reads in the current status of players keys
      myDataP = new LoadVars();
      myDataP.load(" http://www.elementalive.net/keyDown.php");
      myDataP.onLoad = function(){
      stage3player1keyCount = myDataP.info;
      trace(stage3player1keyCount +' this is the key count of player one');

      myDataQ = new LoadVars();
      myDataQ.load(" http://www.elementalive.net/keyDown1.php");
      myDataQ.onLoad = function(){
      stage3player2keyCount = myDataQ.info;

      trace(stage3player2keyCount +' this is the key count of player 2');
      myDataR = new LoadVars();
      myDataR.load(" http://www.elementalive.net/keyDown2.php");
      myDataR.onLoad = function(){
      stage3player3keyCount = myDataR.info;
      trace(stage3player3keyCount +' this is the key count of player 3');
      myDataS = new LoadVars();
      myDataS.load(" http://www.elementalive.net/keyDown3.php");
      myDataS.onLoad = function(){
      stage3player4keyCount = myDataS.info;
      trace(stage3player4keyCount +' this is the key count of player 4');
      this.stage3transferKeyList.setStyle("fontSize", "20");

      myDataT = new LoadVars();
      myDataT.load(" http://www.elementalive.net/wait1a.php");
      myDataT.onLoad = function(){
      player1Name = myDataT.info;
      trace('this is player 1s name'+ player1Name);
      printName(player1Name1, 1);
      myDataU = new LoadVars();
      myDataU.load(" http://www.elementalive.net/wait1b.php");
      myDataU.onLoad = function(){
      player2Name = myDataU.info;
      trace('this is player 2s name'+ player2Name);
      printName(player2Name, 2);
      myDataV = new LoadVars();
      myDataV.load(" http://www.elementalive.net/wait1c.php");
      myDataV.onLoad = function(){
      player3Name = myDataV.info;
      trace('this is player 3s name'+ player3Name);
      printName(player3Name, 3);
      myDataW = new LoadVars();
      myDataW.load(" http://www.elementalive.net/wait1d.php");
      myDataW.onLoad = function(){
      player4Name = myDataW.info;
      printName(player4Name, 4);
      trace('this is player 4s name'+ player4Name);

      trace('1this is player 1s name'+ player1Name);
      trace('1this is player 2s name'+ player2Name);
      trace('1this is player 3s name'+ player3Name);
      trace('1this is player 4s name'+ player4Name);

      Thanks for any help in advance, it is much needed and appreciated.

        • 1. Re: Problems with seeing variables pulled out of database
          blemmo Level 1

          the trace statements at the end of the code get executed right after all the load() calls; it is very likely that the vars didn't finish loading at that moment. To be on the safe side, use those vars in the onLoad event of LoadVars, this makes sure the code executes after the loading finished.

          • 2. Re: Problems with seeing variables pulled out of database
            lsands Level 1
            hi blemmo,

            thanks so much for your reply, totally stumped on this one.
            Just to clarify, do you mean that the variables are being given values but that when they are being printed out at the bottom they are not yet assigned properly? If this is the case, how will I be able to ensure that they have values in time for me to use them elsewhere in the code. Would an interval do the job?

            Thanks again for your help, you're saving a poor master thesis group here :)

            • 3. Re: Problems with seeing variables pulled out of database
              blemmo Level 1
              Well clarified. :)
              To use those vars, you can make use of the onLoad event. Code in this gets executed when the loading finished. The usage of the loaded vars can be placed there, or a function can be called, that uses the loaded values. I like to use nextFrame() to jump to the next frame, and use the vars in that frame.
              Now there are several loading processes, which makes this a bit difficult. Using an interval seems to be a good idea, you can set variables like 'name1loaded' in each onLoad event, and have the interval check all those vars. When all are true, everything is loaded and you can go on.
              Another way might be to load all variables in one go, but then you would need to change the php, so maybe the interval is better.

              • 4. Re: Problems with seeing variables pulled out of database
                lsands Level 1
                I got it working!! thank you sooooo much! You've saved our lives. I'll have to remember this problem..cause I think it might the source of a few other hiccups throughout our game. You've made my day!!