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.

Geek Culture / Declaring a coding state of emergency!

Author
Message
Matt Rock
19
Years of Service
User Offline
Joined: 5th Mar 2005
Location: Binghamton NY USA
Posted: 23rd Apr 2005 07:51
Okay... I'm one of those guys who won't pull over to ask for directions if I have a remote feeling I know where I'm going, unless I'm off someplace that I've never been. As some of you might know, I've assembled a team of artisans to help me make the game I designed. Also, I'm working on a pet project... Well, I've hit a bump, if you want to call it that, with the pet project and I need help!

I'm having a serious issue creating "save game" files. I've been learning this language as I go along and only really programming the media stuff and the front end for my main project... for the pet project, I'm learning stuff bit-by-bit. I figured giving the player the ability to save their game would be easy. The other programmer on my main project deals with memblocks and files and all that, but this is my pet project and I don't want him to simply write it for me and be done with it... I'll never learn that way.

My question:

I have several variables that I need to save to a file and open to read. one of them is a string, and the rest of them are integer values. I tried using the WRITE STRING command for the string and the WRITE LONG command for the integers, but when I later read back the data, the string didn't exist and all of the integers were exactly the same... and the integer didn't even match any of the variables How do I get all of this data into a file, and how do I read it back later so that the proper variables are understood by the rest of the software? I can't find anything in the code base that'll help me with this. Save me!

- Matt whose up "some" creek with no paddle, lol

"Hell is an Irish Pub where it's St. Patrick's Day all of the time." ~ Christopher, *The Soprano's*
Jimmy
21
Years of Service
User Offline
Joined: 20th Aug 2003
Location: Back in the USA
Posted: 23rd Apr 2005 08:00
I'd help you, but my mom taught me that all liberals are prejudice bigots.

Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 23rd Apr 2005 08:08 Edited at: 23rd Apr 2005 08:09
Try writing all the variables to seperate files...i know it's alot of files but if you keep them in a folder they aren't too messy...

and i used write byte for my integers...but you can use long if you want...

"We make the worst games in the universe."

Matt Rock
19
Years of Service
User Offline
Joined: 5th Mar 2005
Location: Binghamton NY USA
Posted: 23rd Apr 2005 08:12 Edited at: 23rd Apr 2005 08:17
LOL

How are liberals prejudice bigots? And isn't "prejudice bigot" a double-negative? And since when are liberals prejudice? I thought popular stereotypes declare that us liberals are the tree-hugging love-everyone people, and you conservatives were the gun-toting bigots

Okay, lets NOT turn this isn't a political debate, like every other thread I've ever posted

- Matt, who can't escape other threads no matter how hard he tries

EDIT: Thanks Peter! I suppose I'll have to write all of these saves to a new folder. Is there any way to combine all of this data into one file? And about bytes vs. long... how large of an integer can "bytes" hold, and how big is it compared to "long?" For instance, for the money variable, would either be better than the other if the player has, say $200 compared to $2,000,000?

"Hell is an Irish Pub where it's St. Patrick's Day all of the time." ~ Christopher, *The Soprano's*
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 23rd Apr 2005 08:44
You could just use write string for everything, and then use val() to convert it back to numbers.

Anyway, what's wrong with the dbpro board?

Facts are meaningless.
You could use facts to prove anything that's even remotely true.
Jimmy
21
Years of Service
User Offline
Joined: 20th Aug 2003
Location: Back in the USA
Posted: 23rd Apr 2005 08:49 Edited at: 23rd Apr 2005 08:52
Quote: "And isn't "prejudice bigot" a double-negative?"


Oh and there you liberals go again, with the fancy talk.

Anywho,

all variables in separate files? that works, but I've done saving and loading is a few of my projects and I've never needed more than one file. I think what I may have done is just converted everything to strings and wrote strings, then read strings and converted back. I'll have to look at my old projects, which takes effort, so I'll get back to you in a couple hours.

I believe bytes are 256
aaand longs should be 32 bit, 2^32, YOU figure it out.

Edit: aahh, you see? David T is teh shizzle, man.

Matt Rock
19
Years of Service
User Offline
Joined: 5th Mar 2005
Location: Binghamton NY USA
Posted: 23rd Apr 2005 08:53 Edited at: 23rd Apr 2005 08:54
Thank you guys, even Jimmy hehe

Um... I thought val() only converted strings to integers? Does it work both ways? Also, can I save multiple strings to one file?

Sorry Dave, hehe... I've never posted anything on the other forums, I dunno, I just posted it here without really thinking about where it should go

- a very greatful Matt

"Hell is an Irish Pub where it's St. Patrick's Day all of the time." ~ Christopher, *The Soprano's*
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 23rd Apr 2005 08:54 Edited at: 23rd Apr 2005 08:57
Quote: " but when I later read back the data, the string didn't exist and all of the integers were exactly the same"

Could you show us some code? Writing that sort of data to files and then reading it back works fine for me.

EDIT: It seems you may be right there. Storing a string after storing an integer doen't seem to work for me.

VAL() converts a value from the string provided, and STR$() converts a value to a string.


"Lets migrate like bricks" - Me
billy the kid
19
Years of Service
User Offline
Joined: 7th Dec 2004
Location:
Posted: 23rd Apr 2005 09:13 Edited at: 23rd Apr 2005 09:16
Well I could help you if you were writing in C++, C#, Java, and a lot of other languages. But I have no idea with DBPro. The most efficient way to do what you want to do is called "serialization". Basically it writes the binary data to a file and allows you to read it back very fast. This also requires putting in some extra info so you know when you have camera data opposed to light data. However I dont know what commands do that sort of thing in DBPro or if they exist. Anyway you could still research "serialization" for the theory and that may help.
Matt Rock
19
Years of Service
User Offline
Joined: 5th Mar 2005
Location: Binghamton NY USA
Posted: 23rd Apr 2005 09:17
Here's the code I'm working with... try not to get any ideas about what I'm making from the variable names, I want that to be a surprise, lol

- Matt

Please note: I tried naming the file "savegame.dat," "savegame.bak," and "savegame.sav"... until I just assumed "savegame" with no extension would work

Thanks!

"Hell is an Irish Pub where it's St. Patrick's Day all of the time." ~ Christopher, *The Soprano's*
Matt Rock
19
Years of Service
User Offline
Joined: 5th Mar 2005
Location: Binghamton NY USA
Posted: 23rd Apr 2005 09:51
I just converted all of the integers to strings, then back again... and this time, everything came out as 0 (zero)... ugh.

I'm hoping I don't have to make individual files for each one... that would be a rather annoying process. The HAS to be a way to get all of them into one file.

- Matt

"Hell is an Irish Pub where it's St. Patrick's Day all of the time." ~ Christopher, *The Soprano's*
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 23rd Apr 2005 09:56
Try taking out make file.


"Lets migrate like bricks" - Me
Matt Rock
19
Years of Service
User Offline
Joined: 5th Mar 2005
Location: Binghamton NY USA
Posted: 23rd Apr 2005 10:05
But if I remove that, how does it know where to save everything to?

"Hell is an Irish Pub where it's St. Patrick's Day all of the time." ~ Christopher, *The Soprano's*
Ace Of Spades
19
Years of Service
User Offline
Joined: 6th Mar 2005
Location: Across the ocean
Posted: 23rd Apr 2005 10:13
Quote: "But if I remove that, how does it know where to save everything to?"


will create it automatically if it does not exist.

Digitalmodr
Coder_David
[Apolloed ]
kenmo2
19
Years of Service
User Offline
Joined: 15th Apr 2005
Location:
Posted: 23rd Apr 2005 10:14 Edited at: 27th Jun 2012 06:38
I think he is right. OPEN TO WRITE automatically creates a new file if I remember correctly.

Also... A byte is 0-255 or -128 to 127, a long is 4 bytes, yes you can save multiple strings to file (all it is just bytes), and finally the filename extension does not make any difference when saving your own file format.

You may have figured those out by now.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 23rd Apr 2005 10:15 Edited at: 23rd Apr 2005 10:16
Exactly. Usually open to write doesn't work if the file already exists.


"Lets migrate like bricks" - Me
Matt Rock
19
Years of Service
User Offline
Joined: 5th Mar 2005
Location: Binghamton NY USA
Posted: 23rd Apr 2005 10:20
YESSSSSS!!!!!! Thank you!!! I removed those lines, figuring "eh, nothing else's worked," and sure enough, wham, problem solved to be honest Benjamin I thought you were pranking me, hehe. And although it turned out I didn't need your help, thank you Apolloed for explaining it to me I owe you guys big, hehe, perhaps I should give you guys copies of my game when it's finished... although I can't rightly see why you'd want to play it, seeing that it's a text game, and all of the graphics are still bmp's I made in ms paint, hehe. But still, if you want, I'll gladly send a copy to you guys when it's done ... pretty much the best "thanks" I can conjure

- Matt

"Hell is an Irish Pub where it's St. Patrick's Day all of the time." ~ Christopher, *The Soprano's*
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 23rd Apr 2005 10:23
Heh, you're welcome


"Lets migrate like bricks" - Me
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 23rd Apr 2005 10:26 Edited at: 23rd Apr 2005 11:41
[edit]nm

*goes sulk in a corner*

AphoticVM status: 30% (Yes, that number just went down.) AphoticBasic status: 10%
UnderLord
21
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 23rd Apr 2005 12:02
Damn gun toting.....oh wait this thread is over ookie

When we talk to god, we're praying. When god talks to us, we're schizophrenic.
Schizophrenic beats eating alone.
Ace Of Spades
19
Years of Service
User Offline
Joined: 6th Mar 2005
Location: Across the ocean
Posted: 23rd Apr 2005 12:07
Quote: " seeing that it's a text game"

Quote: "all of the graphics are still bmp's I made in ms paint"


Erm...ok? I suppose that could make sense.

Digitalmodr
Coder_David
[Apolloed ]
Matt Rock
19
Years of Service
User Offline
Joined: 5th Mar 2005
Location: Binghamton NY USA
Posted: 24th Apr 2005 05:57
Well... it started out as a text game, you walking about in a city, but I felt like it was too limited and simple, so what started out as an adventure to save your girlfriend (classic video game scenario) transformed into an RTS... how, I'm not sure. Right now it's sort of like "Romance of the Three Kingdoms" by Koei for the SNES, but for combat there's just text over a still image with corny free sound effects I've collected from the net. No bmp took longer than four minutes to throw together... so I'm sure you can all imagine how classic this game'll turn out to be, lol.

- Matt

"Hell is an Irish Pub where it's St. Patrick's Day all of the time." ~ Christopher, *The Soprano's*
JerBil
20
Years of Service
User Offline
Joined: 8th May 2004
Location: Somewhere along the Z axis...
Posted: 24th Apr 2005 11:32
And you must delete a file before you can write new data,
if it already exists. I do this code before I write to the cfg file. Also make sure you're in the right directory.



-JerBil

Ad Astra Per Asper

Login to post a reply

Server time is: 2024-11-15 01:03:58
Your offset time is: 2024-11-15 01:03:58