File position?

Previous topic - Next topic

S. P. Gardebiter

Is there a way to jump to a file position?
I really need it in order to make an editor for a game.
If there is no possibility I hope there will be a command for this in the next version.
~ Cave Story rules! ~

Moru

No there is no way of jumping to a position in a file, you have to read each byte up to the position you want. ( I have already wished for this function :-)

If it is a small file you can read the whole thing into an array and work with that instead, should make it a lot faster.

Ian Price

Most game editors use arrays, as Moru suggested above. Arrays are extremely versatile and can be used for absolutely anything that requires values or strings.

You are better off manipulating an array than constantly searching, loading and saving to a file on your harddrive anyway.
I came. I saw. I played.

AndyH

Also take a look in the samples folder.  There is a MEMBANKS example in there, there are functions to create, read from, write to and free created memory at the byte level.  (be nice if these command were built in ... hint ;))

What I did in Mouth Trap was to use a membank that was the size of (LevelSize * numberOfLevels).  I load my level data into the bank using the normal file commands, then I can PEEK any byte in there.

I did use a TYPE which had some arrays and properties for a single level and I have a LOAD and SAVE level function to transfer the chosen level from the membank (eg: memBankPosition = levelToLoad * LevelSize) to an instance of the TYPE for easy access -it's simpler to access named arrays and element and property names than offsets in memory and if I decide to change the format of my level data it's easier to manage this way.

Be aware, especially on PPC and GP2X that have limited memory, that array elements take up four bytes each, so if you uses these exclusively instead of memory banks and you are not using 32 bit numbers then you will be using four times as much memory as you need.  You could compact four bytes worth of data into a single array element but I think that's just making it hard work for yourself.  

This is only an issue if you plan to use very large arrays, as the membanks may be more suitable (not always).  You've just got to weigh up what is more appropriate to use for the task at hand.  Hope that helps.   PS:  Yes I would like a file seek command too, good for simple database access :)

S. P. Gardebiter

The file I want to edit is about 1 MB big, also the positions are very different.
So yeah, I really would need such a function :/
~ Cave Story rules! ~

Kitty Hello

You can easily read a 1MB file into memory (on PC).

S. P. Gardebiter

Quote from: GernotFrischYou can easily read a 1MB file into memory (on PC).
I know, still it's alot of work.
Is there a chance, that such a command will ever be made?
~ Cave Story rules! ~

Kitty Hello

Why not reading dummy bytes? Usually you load the level sequntially into an array. Don't load the level at runtime (while you are scrolling)

S. P. Gardebiter

This is not about loading levels, it's about loading code from a executable file.

It's not going to be a normal level editor, it will edit much more things, like reverse engineering, that's why I need the command.

It's not the best method to load so much data then wait for it to load, then again when it's on the end of the file load then again and again because I need some offsets at the start, then go to the middle again and if I need to go back, then again load them and check if it's at the end of the file. Not the very best thing but well :|
~ Cave Story rules! ~

AndyH

Could you not load the entire file in to memory (eg: membanks) and then just look up the bits you need, make changes if required and write back the changes at the end when you are done?   It would probably be much quicker and the amounts of RAM on desktop's devices is not so limited as it used to.  Even if you planned to run on a GP2X, you've got quite a few Mb's to play with.

BTW, is it Cave Story you'll be editing by any chance :)

S. P. Gardebiter

That's a nice idea :P Thanks.
And yes, it's Cave Story.
~ Cave Story rules! ~

FutureCow

Sorry to resurrect such an old thread - the membank example seems to have disappeared. Does anyone still have it lying around (or a better way of inline editing a file?)

Kitty Hello

There's a command FILESEEK now.

FutureCow

Thanks Kitty Hello. Fileseek I found, I was after the membanks example so that I could easily edit halfway through a file without truncating the contents from that point onwards.