TGC Codebase Backup



Reading .txt files principles by MikeS

22nd Mar 2004 19:25
Summary

Learn how to read strings from a .txt.



Description

Learn how to read strings from a .txt.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ` This tutorial was created by Yellow -Mike- 3-12-04
` Although not necessary, it would be nice to be credited and
` notified at yellow1dbp@hotmail.com if this was used in a game
` Thanks, and I hope the tutorial helps.

`Reading text from a file

`It's important to set the directories up correctly, so you're reading the
`right file.
set dir "INSERT FILEPATH HERE C:\...\MyGame"
open to read 1,"INSERT TEXT FILE TO LOAD"

read string 1,text$ `Name the variable you'll hold for the string you're loading.


do `Initialize our loop

print text$ `Print the variable from the first string

if escapekey()=1
 close file 1 `Closes the file
 end `Ends the program
endif

loop `Loop our program

`You now know how to read strings from a file. This can be useful, when
`you want users to be able to tweak settings for your game. A combination
`of 'if statements' can give the users full flexibility over a game.


`Hope this helped
`Copyright(c) CurvedBasic 2004