1. I'm trying to show how far a for..do loop has progressed, but can't seem to get it to work. My screen shows a Button and a FontString, the text of the FontString to show "Percent of loop complete : ".. followed by the percentage value of 10,20 etc..

    Very simply the code is :

     function myButtonOnClick()
         local myPercent
         for myLoop=1,10 do
             myPercent=math.floor((myLoop/10)*100)
             myFontString1:SetText("Percent of loop complete : "..myPercent)
             myOneSecondDelay()
         end
     end
    
     function myOneSecondDelay()
         local delay
         delay=time()
         while time()=delay do
         end
     end
    

    (The reason for the 1 second delay routine is that otherwise the whole routine finishes too fast for me to see what is going on.)

    What actually happens is that everything freezes for 10 seconds and the FontString only shows the final message of "Percent of loop complete : 100". What I probably need is some way of refreshing the frame after setting the FontString text so that it is displayed. I've tried reading the code for Auctioneer (which uses a status bar to show how far it has progressed), but that code is too complicated for a novice like myself.

    Any ideas would be helpful. Thanks

  2. You'll need to create a dummy frame and give it an OnUpdate script. In that script, check how much time has passed, and if it exceeds some threshold value (a tenth of a second, perhaps), update your display.

    You'll probably have to rework your code so that the execution happens in small "chunks" over time, instead of in one big loop. If it "finishes too fast" for the execution to be noticable, I'd question whether or not you should bother. Progress bars and the like are just a tool to let the user know that the computer didn't lock up in the middle of a massive task.

  3. Thanks for your reply and I'll look into the idea of dummy frames and the OnUpdate scripts. My intended use for this code is to eventually show the progression of reading the whole of the Auction House (some 15000+ records) and not just counting to 10. I used 1,10 in my above code to keep things nice and simple.

  4. I think I got it sussed. Its a bit verbose, and can probably be tidied-up a lot, but it works and so the general idea must be right. Thanks for your hint regarding OnUpdate.

    I realised that just reading one record every time the Update fired would take around 15000/60 seconds (assuming 60 updates per second). This would mean 250 seconds (or 4 over 4 minutes) to read the entire AH. For this reason I made the for..do loop read 10 records every time the update fired, which is the reason for all the checking of start and finish values.

    Even if I missed a few updates because of the rest of my code running, it still takes between 30-60 seconds to read the AH, which is not too bad.

     local myStartValue=1
     local myFinishValue=10
     local ButtonHasBeenClicked=0
     local HowManyAHRecords
     -- the variable HowManyAHRecords is set at another part of my program
     -- to hold the total number of records in the AH (usually 15000+)
    
     function myButtonClick()
         ButtonHasBeenClicked=1
     end
    
     function DoMyLoop()
     -- this bit just makes sure we dont try and read past the end of the AH
    
         if myFinishValue>HowManyAHRecords then
        myFinishValue=HowManyAHRecords
         end
         if myStartValue>myFinishValue then
        myStartValue=myFinishValue
         end
    
     -- now we know the start and finish values are valid, the actual AH reading can be done
         for myLoop=myStartValue,myFinishValue do
              [the rest of my code for reading the AH goes here]
         end
    
    
     -- now check if the end of the AH has been reached and stop the MyUpdateRoutine from
     -- passing control to DoMyLoop() by setting ButtonHasBeenClicked to zero
    
         if myFinishValue==HowManyAHRecords then
              ButtonHasBeenClicked=0
         else
        myStartValue=myStartValue+10
        myFinishValue=myFinishValue+10
         end
     end
    
     function MyUpdateRoutine(self,elapsed)
         if ButtonHasBeenClicked==1 then
             DoMyLoop()
         end
     end
    

    Dont forget the <Scripts> part of the XML needs this line adding:

     <OnUpdate>MyUpdateRoutine(self,elapsed)</OnUpdate>
    

    I put the code here incase anyone else was having problems and wanted to know how to do it. Please - anyone with better suggestions on tackling this problem, give us your code here.

    Once again, thanks for your help.

    p.s. sorry for the way this has displayed - i used the usual code block markers, but kept getting a message : XSSFilter could not parse (X)HTML:

  5. In order to use the code button, you must highlight the block of code and then click it. The reason you were getting the XSS error was because you didn't put <Scripts> in a code block. Not user friendly, but I'm working on it. Thanks for reporting back your findings.