Can't Read Strings

BlitzPlus Forums/BlitzPlus Programming/Can't Read Strings

Zooker(Posted 2005) [#1]
I can't get this to read a string Correctly> No matter what I do it will not read x$ as "Howard". Please tell me how to do this because my whole program revolves around reading & writing files?

Global x$ = ""
Global y = 0
Global z# = 0
A$= SaveGame(1)

B$=LoadGame(1)

WaitKey()
End
Function SaveGame(a)

;set up the screen
Cls
Locate 0,0
;let user choose what to save game as
filesave = Input("Save game as - ")
filesave = filesave + ".dat"

;write files to dat file
fileout = WriteFile(filesave)
x$ = "Howard"
y = 880091
z# = 11.9
;enter any other variables included in any games here.

WriteInt(fileout,x$)
WriteInt(fileout,y)
WriteInt(fileout,z#)
;for extra variables, use "WriteInt," "WriteString," and "WriteByte" accordingly.

;close file
CloseFile(fileout)
x$ = ""
y = 0
z# = 0
End Function


Beaker(Posted 2005) [#2]
Change..
WriteInt(fileout,x$)
WriteInt(fileout,y)
WriteInt(fileout,z#)

to..
WriteString(fileout,x$)
WriteInt(fileout,y)
WriteFloat(fileout,z#)



Regular K(Posted 2005) [#3]
Your trying to write a string as an integer, and a float as an integer! You gotta write the variable to the file as the same type as it is or you will get problems.


Zooker(Posted 2005) [#4]
So I found out. Sorry I should of seen that easy but i was up way beyond my snooze time.