grov
03-03-2006, 11:30 AM
Hi people,
I'm trying to create a kind of model database file containing some stuff. Right now it looks like this:
[1]
modelData1
modelData2
[2]
modelData1
modelData2
[3]
modelData1
modelData2
[4]
modelData1
modelData2
What I would like to do is to be able to update this data through a script.
I figured I'd do it by updating one "block" at a time (both model data strings).
So, the code for this would be something like:
modelID = "1"
newData = "New data 1\nNew data 2\n"
f = openFile "c:\\modelData.dat"
skipToString f ( "[" + modelID + "]\n" )
firstBlockEnd = (filePos f) - 1
seek f 0
firstBlock = readChars f firstBlockEnd
skipToString f "[" -- this won't work for the last model, but nevermind that
seek f ((filePos f) - 1)
secondBlock = readChars f 99999 errorAtEOF:false -- crappy temporary code again
close f
format "%%%" firstBlock newData secondBlock to:(newScript()) -- just testing what it'll look like
So, running this script with modelID = "1" works fine:
[1]
New data 1
New data 2
[2]
modelData1
modelData2
[3]
modelData1
modelData2
[4]
modelData1
modelData2
modelID = "2" gives me this result:
[1]
modelData1
modelData2
[2]
modNew data 1
New data 2
[3]
modelData1
modelData2
[4]
modelData1
modelData2
and modelID = "3":
[1]
modelData1
modelData2
[2]
modelData1
modelData2
[3]
modelDNew data 1
New data 2
[4]
modelData1
modelData2
Any ideas why this might happen, or rather, what I'm doing wrong? :)
Thanks!
I'm trying to create a kind of model database file containing some stuff. Right now it looks like this:
[1]
modelData1
modelData2
[2]
modelData1
modelData2
[3]
modelData1
modelData2
[4]
modelData1
modelData2
What I would like to do is to be able to update this data through a script.
I figured I'd do it by updating one "block" at a time (both model data strings).
So, the code for this would be something like:
modelID = "1"
newData = "New data 1\nNew data 2\n"
f = openFile "c:\\modelData.dat"
skipToString f ( "[" + modelID + "]\n" )
firstBlockEnd = (filePos f) - 1
seek f 0
firstBlock = readChars f firstBlockEnd
skipToString f "[" -- this won't work for the last model, but nevermind that
seek f ((filePos f) - 1)
secondBlock = readChars f 99999 errorAtEOF:false -- crappy temporary code again
close f
format "%%%" firstBlock newData secondBlock to:(newScript()) -- just testing what it'll look like
So, running this script with modelID = "1" works fine:
[1]
New data 1
New data 2
[2]
modelData1
modelData2
[3]
modelData1
modelData2
[4]
modelData1
modelData2
modelID = "2" gives me this result:
[1]
modelData1
modelData2
[2]
modNew data 1
New data 2
[3]
modelData1
modelData2
[4]
modelData1
modelData2
and modelID = "3":
[1]
modelData1
modelData2
[2]
modelData1
modelData2
[3]
modelDNew data 1
New data 2
[4]
modelData1
modelData2
Any ideas why this might happen, or rather, what I'm doing wrong? :)
Thanks!
