Well, I don't really know off-hand where to find one, but I can tell you what you'll probably need to know about memblocks for doing what you're doing.
A memblock is exactly as its name suggests: a block of memory. You can think of it as a long string of bytes, each with a number attached to it. DarkBasic has added commands to read and write images, sounds, meshes, and arrays to and from memblocks, but essentially, that's all they are, a string of bytes.
What you're going to need to do, is be able to read and write numbers to and from memblocks. Like for instance, the number of enemies the player has killed, or a list of flags for determining which achievements have already been unlocked.
To make a memblock, use the
make memblock command. So, to make a memblock that is 20 bytes long, you'd do this:
That creates memblock number 1. You can get the size in bytes of a memblock by calling the function
get memblock size(memblock number
).
Back to the string of bytes, as I said, each byte has a number associated with it. The bytes are numbered from 0 to
get memblock size()-1. Because all the bytes are numbered and you'll have to give a byte number whenever you read from or write to a memblock, memblock structure is very important. Make sure you've worked out a structure for yourself, so you know where to write what information.
To write numbers to a memblock, you really have to know certain things about the numbers you're trying to write. Important things to know are things like type and size in bytes. DarkBasic gives you the option of writing single bytes, words, and dwords of information to a memblock. A byte is just that, a single byte. A word is a piece of information that is two bytes long and a dword (double word) is four bytes long. Additionally, you can also write a float to a memblock that takes up four bytes as well.
If the number you're trying to write to the memblock is an integer, you'll want to use a byte, word, or dword. Bytes and words can only contain positive integers while dwords can contain both positive and negative. You can use the size of the number to determine which type of information to write to the memblock. Here's a small size reference (all ranges are inclusive of endpoints):
BYTE: 0 to 255
WORD: 0 to 65535
DWORD: -2147483648 to 2147483647
Use a float to store any real number that isn't a positive integer.
Just to clarify the indexing of bytes, when you store a piece of information that is greater than one byte long, it takes up the next few bytes as well. Suppose you wanted to store a dword at the 3rd byte (actually the 4th, all indexed at zero) in a memblock. You'd do this:
write memblock dword 1,3,1234567890 `memblock number, byte number, dword
This takes up bytes 3,4,5, and 6. The next available byte would be byte 7.
Here's a list of commands to write information:
write memblock byte memblock number, byte number, byte
write memblock word memblock number, byte number, word
write memblock dword memblock number, byte number, dword
write memblock float memblock number, byte number, float
These commands return the byte, word, dword, or float stored at the specified byte number.
memblock byte(memblock number, byte number
)
memblock word(memblock number, byte number
)
memblock dword(memblock number, byte number
)
memblock float(memblock number, byte number
)
Now, of course, to actually store any of this, you'll have to write it to a file as I suggested in my earlier post. You can use the
write memblock and
read memblock commands to write and read a memblock to and from an open file. Syntax is as follows:
write memblock file number, memblock number
read memblock file number, memblock number
Whew. That is quite a post... ask if you have questions.