Thanks for the replies. Mobiius, yes I check if the old file exists and delete it prior to downloading the new file.
BatVink - I don't change any of the folder settings so assume all my downloads go to the "write" folder, where I then read them in from there using 'Open to Read'.
Here is my main function to download the file from the server:
Function DownloadSEASONFile()
value = 0 rem set this as failure until file is downloaded
host$ = "excel.starting11stats.co.uk"
file$ = "ppfmseason.txt"
rem delete any existing file first
If GetFileExists("ppfmseason.txt") = 1
DeleteFile("ppfmseason.txt")
EndIF
Rem Display MessageBox
DrawImage(1,970,5,100,100,1080,520)
SetSpriteDepth(970,2)
rem text
BoxText(1,"Downloading Season Best High Scores.....",640,260,950,2,44,-13,1)
SetTextDepth(950,1)
Sync()
Pause(0.5)
http = CreateHTTPConnection()
SetHTTPHost(http, host$ , 0, "","")
//Print ("Connecting...........")
Sync()
//Initiate the request - I prefer async so we can give the user a waiting screen while the connection is working.
SendHTTPRequestASync(http , file$ , "")
time0 = GetMilliseconds()
timeElasped = 0
done=0
repeat
timeNow = GetMilliseconds()
timeElapsed = (timeNow - time0)
rem Print("Connecting to ICC FC server.......") //Here we'd have an actual waiting animation or message.
ready = GetHTTPResponseReady(http)
if ready <> 0 or timeElapsed > 60000 //set a timeout limit
done = 1
endif
Sync()
until done = 1
if ready = 1
// We got a response! We're not using response codes this time for simplicity.
GetHTTPFile( http, file$, "ppfmseason.txt" )
while GetHTTPFileComplete(http) = 0
//Print ("Downloading: " + str(Round(GetHTTPFileProgress(http)))+"%")
Sync()
endwhile
//Print ("Downloading: " + str(Round(GetHTTPFileProgress(http)))+"%")
Sync()
value = 1
elseif ready = -1
//Report there was a connection error - this could happen due to a lost internet connection or the server failed to respond.
//msgbox = MessageBox(1,"There was a problem with the connection","OK","", "Please try again later","",4,0)
DeleteText(950)
DeleteSprite(970)
MessageBox(0,"There was a problem with the connection","Please try again later","","","OK","")
endif
CloseHTTPConnection(http)
DeleteHTTPConnection(http)
DeleteText(950)
DeleteSprite(970)
EndFunction value
I've set a message before and after to make sure the file doesn't exist prior to calling the function and that it does afterwards with no issues. I think it's something to do with this function. If I run this code now and then just opentoread the txt file, the first line I'm getting using Read line is "1000000,Unknown,Unknown,420,1,0,0,0,0" but I know the text file online the first line is "1000000,94fd,John,420,1,0,0,0,1" as I changed it about half an hour ago. I thought it was a cache issue as yesterday it wasn't even showing the first line as the Unknowns but today it is. Then when I update the text file manually online and then re-run, it appears to download the new file but it still shows the old data? So now I'm a bit stumped! Would appreciate any feedback, especially if you can spot something wrong with this function!
El Presidente