Author Topic: Need help with File I/O  (Read 1794 times)

Offline johngood

  • Mc. Print
  • *
  • Posts: 34
    • View Profile
Need help with File I/O
« on: 2009-Apr-18 »
Hi,
I have neen using Basic4ppc to write a boulderdash type game for the Pocket PC.
I have now changed over to GLBasic because I think it is more suited to game
programming, however I have run into problems with File I/O.

In the past I have written a basic map creator in VB6 which creates the following
text file.

5111113014114111
4222222022222221
3241111111111124
2211222222121121
4241241114124121
1214212122121121
1244212142121421
1243212112121124
1244212112121121
1211233222121121
1244211111421121
4243222222221121
1211111111143421
1211141111113121
1211111111113121
4211311111311124
1222222222222221
4111411111411114

I have inserted returns in the file for viewing only, the file is one long line of ASCII text.

This map will grow in size as I get scrolling to work!

My application reads this text file and places graphic tiles which I have created
accordingly to match each number.

I read each value into an array StrData[288] as follows:
for nf = 1 to 288
c = FileGet(chan,nf-1,1) //one char at a time
StrData[nf) = c
next
FileClose(chan)


I cant seem to duplicate this in GLBasic File I/O  :S
Dell Dimension 9200: Core 2 Duo 2.40GHz, 2GB Ram, ATI Radeon X1300Pro, Windows XP Pro SP3
Intel Mac SnowLeopard 10.6.4 Core 2 Duo 2.4GHz 2GB Ram
iPod Touch 2G 4.0 16 GB, iPod Touch 4G 4.1 32 GB

MrTAToad

  • Guest
Re: Need help with File I/O
« Reply #1 on: 2009-Apr-18 »
Have a look at the File I/O examples.  Your problem can be solved by :

  • Using GETFILE to read each line and then process each character
  • ]se READBYTE to read in each character, but make sure you ignore any CR/LF characters.
  • Use READLINE and then process each character
A quick example :

Code: (glbasic) [Select]
handle%=OPENFILE(1,"file.txt",TRUE)
READBYTE handle%,one%
WHILE ENDOFFILE(handle%)=false
    ...process data...
   READBYE handle%,one%
WEND

Offline johngood

  • Mc. Print
  • *
  • Posts: 34
    • View Profile
Re: Need help with File I/O
« Reply #2 on: 2009-Apr-19 »
Thankyou MrTAToad for your helpfull quick responce.  :good:

All is now working fine.  =D

BTW there is only one File_IO example and it only uses PUTFILE and GETFILE
with a randome number not exactly very usefull!

Examples of each File I/O command similar to the way you have explained would
have been much better!

Thanks once again.

JohnGood.
Dell Dimension 9200: Core 2 Duo 2.40GHz, 2GB Ram, ATI Radeon X1300Pro, Windows XP Pro SP3
Intel Mac SnowLeopard 10.6.4 Core 2 Duo 2.4GHz 2GB Ram
iPod Touch 2G 4.0 16 GB, iPod Touch 4G 4.1 32 GB

MrTAToad

  • Guest
Re: Need help with File I/O
« Reply #3 on: 2009-Apr-19 »
Yes, I was expecting more file i/o example programs there - but at least you got it going!