Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Achievements

Author
Message
Panda games
15
Years of Service
User Offline
Joined: 30th Sep 2008
Location:
Posted: 27th Jan 2009 15:18
I was wondering if any one had a code to make Achievements, save them to your computer and make them unlock stuff.

Thanks,
Pandagames

http://www.pandagames.org
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 28th Jan 2009 09:52
theres probably heaps of ways to do this, but if you better explain maybe someone can be more specific with thier code...
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 29th Jan 2009 04:32
you have to make a memblock but it depends on what exactly you need to do for me to give you more detail. but i suggest looking into memblocks. there will be lots of tutorials on them i believe.
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 29th Jan 2009 05:08
Hm? There's no reason you have to make a memblock. As lucifer 1101 said, there's plenty of ways for you to do this. Just simply writing the data to a file will do.
Panda games
15
Years of Service
User Offline
Joined: 30th Sep 2008
Location:
Posted: 29th Jan 2009 20:35
Where can I find a tutorial on memblocks? Also by achievements I mean "Kill 50 enemies" and it unlocks mini-games or new colors.

PandaGames

http://www.pandagames.org
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 30th Jan 2009 00:29
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:



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.
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 30th Jan 2009 00:54
i have a couple of questions

1. this can be used to save game informatio right?

2. if i was to write a variable of each type to a file, what format would the file be in?

3.if it is readable by notepad or something similar what would the layout be like?

4. and last but not least if it can be read like in question 3 how could i go about protecting that information?


sorry i thaught i should ask as im now interested in what memblocks are exactly...
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 30th Jan 2009 01:07
Nice post Kira!
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 30th Jan 2009 01:17
Ah, lucifer 1101, I see you're still on that mandatory probation period thingy... who knows when your post will actually show up. I still got the email about it though. I'll respond when it actually does.

Thankee, revenant chaos!
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 30th Jan 2009 03:59
Here are some answers:

1. Yes, you can store just about anything you want to in a memblock.

2. I assume you're talking about the file extension? The extension of the file is not determined by what is stored in it. You must seperately open a file using open to write at which point you may give the file any name and extension you want.

3/4. Writing the byte 123 is different than writing each of the three characters "1","2", and "3", which is something that would display nicely in notepad. Typically, when writing bytes of information and displaying them in notepad, you get some kind of gibberish. However, I happen to know that the byte 123 codes for the character "{".
So, to answer your question, what you store in memblocks is not readable with notepad or some other text editor. If you really want to get into it, you'd have to use a hex editor and even then, there'd be no real way of knowing where one number that was written ends and where another begins. If you'd like me to, I can explain how bytes are organized when they're written to a file.

So, back to question 2, here's a little example demonstrating how to write to a memblock, write that memblock to a file, read that memblock from a file, and read from that memblock:



Also, if you're so possessed, you can write multiple memblocks to one file. Just be sure to read them out of it in the same order you wrote them in.

Feel free to ask questions.
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 30th Jan 2009 04:21
wow thanks for that, i was just a little worried that if someone could open thier save file they could actually change values...
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 30th Jan 2009 05:24
No problem.

But yeah, I think they'd be hard pressed to change anything with a useful consequence.

Login to post a reply

Server time is: 2024-09-28 02:23:23
Your offset time is: 2024-09-28 02:23:23