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 / Memblocks help...please!!!

Author
Message
Francesco
20
Years of Service
User Offline
Joined: 11th Apr 2004
Location: Milan, Italy
Posted: 5th May 2004 23:35
Hi everybody,
I wrote this little code
to make a simple score ranking in a game. It seems to work at first, but sometimes the scores it shows are different from what the scores really are...how is that possible...a bug maybe...or perhaps because I suck at coding??
PLEASE HELP!!!

Non si inalberi mica con me, sa!
Lei è venuto qui, lei ha il tombino intasato!
Siamo uno spurgo serio, noi!
Atreides
21
Years of Service
User Offline
Joined: 11th Oct 2003
Location: Switzerland (but NOT on a mountain !)
Posted: 6th May 2004 00:24 Edited at: 6th May 2004 00:25
yap, I know what's the problem
(sh*t, I've a problem with my navigator, the font of the forms is almost unreadable ahh, it's ok now )

look at the help file of "read memblock float" :
The Position value is specified in bytes.

a float isn't stocked in only one byte, and in your program, you're using memblock as if there was only one byte for a float

look at this code :


it writes a float in a memblock (I choosed a random float), and then, it reads the memblock until there's nothing written in it anymore => there are, as you can see, for bytes for a float

so, your code should look like it (maybe not exactly like it : I can't test it, so you might have to change something )

for writing :
write memblock float 1,b*4,score

and for reading :
text 0,100,"SCORE 1: "+str$(memblock float(1,1*4))+""
text 0,120,"SCORE 2: "+str$(memblock float(1,2*4))+""

but .. using memblocks isn't the best way to stock highscores.. if I were you, I'd use an array, it's easier to use, and you can use the type you want without playing with how is stocked the data

P.S.: haha, the forum forbid words like sh... hmm.. I can't say it because if I do, I won't be able to edit my post ^^

The sleeper must awaken !
Francesco
20
Years of Service
User Offline
Joined: 11th Apr 2004
Location: Milan, Italy
Posted: 6th May 2004 18:01 Edited at: 6th May 2004 18:04
Yeah, you're right. That was the problem. I'm going to try to use an array...but then can I save it to a file?
PS: How do files work? I mean, if you already have an existing file, can you write to it? When I try to use the "open to write" command and the file I try to write on already exists, the compiler gives me an error...WHY???
Thanks!

Non si inalberi mica con me, sa!
Lei è venuto qui, lei ha il tombino intasato!
Siamo uno spurgo serio, noi!
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 6th May 2004 18:57
You can't append to a file.
You also need to check if the file exists and delete it if it does before opening.
if file exst("file.txt") then delete file "file.txt"
open to write 1,"file.txt"

i won't see you in the pit
Francesco
20
Years of Service
User Offline
Joined: 11th Apr 2004
Location: Milan, Italy
Posted: 6th May 2004 21:15
Hey, I worked one hour fixing my code. It worked finally...but then....NOOOO! I built it in an exe file, and it didn't work!! WHY?? WHY ME?? Can someone check my code? Can you try to build it on your computer? You can find code and media in the code base, or you can add your own media to my code
. PLEASE HELP!

Non si inalberi mica con me, sa!
Lei è venuto qui, lei ha il tombino intasato!
Siamo uno spurgo serio, noi!

Login to post a reply

Server time is: 2024-11-26 17:27:53
Your offset time is: 2024-11-26 17:27:53