#1 20-02-2010 21:45

Trickstar
Registered: 20-02-2010
Posts: 4

Help understanding 0A9D

I'm trying to write a script that uses the users input using a text file and from what I got from the Sanny help files, I could use 0A9A: $hFILE = openfile "CLEO\file.txt" mode 0x72, to read it as a text file and read the integer put inside the file by the user, but it didnt work when I tested it. The way it was supposed to work is that the user is supposed to use the empty file and type a number 1-9999, meaning the file will be empty besides a number "999" ect. and I wanted my script to read it like that so I can use it in my conditions later in my script.

This is what I tried, I don't get a crash but it doesn't do anything, meaning its isolated to this part of my code.

0A9A: $hFILE = openfile "CLEO\mp3.txt" mode 0x72  // IF and SET
0A9C: 0@ = file $hFILE size
if 0@ > 4
then jump @FAIL
end
0A9D: readfile $hFILE size 0@ to $150
008A: $150 = 1@ // (int)
0A9B: closefile $hFILE

Offline

#2 29-03-2010 03:35

Deji
From: UK
Registered: 09-11-2008
Posts: 189
Website

Re: Help understanding 0A9D

Try this...

// Make sure we have the file opened before continuing.
repeat
	wait 0
until 0A9A: 0@ = openfile "CLEO\mp3.txt" mode 0x72

0A9C: 1@ = file 0@ size
if
	1@ < 1 // make sure the user has typed something.
then
	jump @fail
end

// We only need the first 4 bytes. That is enough for a number.
// Anything longer will simply be cut-off, but that doesn't matter. Your code was pretty much doing the same.
0A9D: readfile 0@ size 4 to 2@
0A9B: closefile 0@

One thing I'm not sure of is the mode. There be problems with understanding what the heck that be meaning, savvy?

Offline

Board footer

Powered by FluxBB