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 / Saving my game- dont understand it fully- HELP!!!

Author
Message
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 7th Oct 2003 21:24
Hi there, this is proberly the most simple question to ask, but i want to save my game, well i got the codes but dont understand.
Look at this code:


Now i sort of like copied this, i looked at it and did understand it, but what i didn't get is the codes like:


i understand the write word 1, but when it comes to HeroPrimaryStats(1).strength i do not have a clue.
I guess this will save the heroprimarystates for the strength?

My game, say i want to save the current Magic points for my hero would i need the HeroPrimaryStats(1)? if i didn't waht would the basic code be needed?

Thanks for reading.
Andrew

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
PoHa!84
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: To your left.
Posted: 7th Oct 2003 21:59
Quote: "i sort of like copied this,"


You mean you copied both and just put them into your game or what? Looking at your code, I have no idea what exactly that HeroPrimaryStats(1).Strength would do. Um... I guess I'm pretty much useless then, aren't I?

Destroy you with my mind, I could!
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 7th Oct 2003 22:07
all that heroPrimaryStat stuff is a UDT, or user defined type, i have no idea exactly what they do or how to use them but all you need to do is write the main stats to a file then read them back into your program


Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 7th Oct 2003 22:21
Ok i will try that, thanks,

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 7th Oct 2003 22:46
Also 1 other simple question, why do some codes, down the bottom have like endif more than once?
like
endif
endif
endif

instead of endif??

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
PoHa!84
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: To your left.
Posted: 7th Oct 2003 22:55
because they had multiple unclosed 'if' statements.

Destroy you with my mind, I could!
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 7th Oct 2003 23:12
I'm still not with you?

Can you show me an example please?

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 7th Oct 2003 23:20
if <condition>
if <condition>
if <condition>
<do something>
endif
endif
endif

used when you need to check multiple conditions before doing something, looks neater than if <condition> and <condition> and <condition>


PoHa!84
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: To your left.
Posted: 7th Oct 2003 23:26
In other words for every 'if' condition, there must also either be a 'then' or an 'endif' to er... "close" it.

Destroy you with my mind, I could!
Tariq Hussein
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location:
Posted: 7th Oct 2003 23:27
Hi there! A user defined type is easy to define. The code you posted:
Write Word 1,HeroPrimaryStats(1).Strength

Has a variable with which was created with a user defined type. To create a user defined type you would do the following:
TYPE MyHero
Strength as INTEGER
ENDTYPE


A user defined type is created using the TYPE keyword. The name MyHero shown in the example is your own created type. In fact the type above is actually is using a type itself (Strength is defined of type INTEGER!). Once you have defined a user type you need to create an instance of it (well in object orientated terms but this is far more simpler and more comparable to C's struct then C++'s OO features). To do this somewhere in your code you would do the following:
HeroPrimaryStats as MyHero

Once you have created an instance of your type you can then access your newly created variable like this:
HeroPrimaryStats.Strength = 100

As you can see Strength was actually defined in the type but you need to use it in the above manner. Considering that your code is an array you can still define your variable as an Array like this:
Dim HeroPrimaryStats(100) as MyHero

Simply put I've created 100 heros (why I have absolutely no clue).
Each hero will store its own value which means doing this:
HeroPrimaryStats(0).Strength = 100

Will not change this!
HeroPrimaryStats(1).Strength

I hope this helps and it is Dark Basic Pro's (i dont think classic
has this) most powerful programming tools so use it wisely!

When I turned 2 I got worried, in 1 year my age doubled!
PoHa!84
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: To your left.
Posted: 7th Oct 2003 23:32
Oh! This is a pro question! Well, you can disregard my post...


Destroy you with my mind, I could!
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 7th Oct 2003 23:42
Cool, this is great, thanks for the time and help.

Sounds great

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
Rwilson
21
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 8th Oct 2003 08:49
Whoah! Never expected any of my code to be used as an example by someone else! I feel so... Honored .
Anywho, Tariq Hussein hit most of the User-Defined-Type stuff right on the nail head, so I won't do to much more on that than show you how I defined HeroPrimaryStats:




If you would like me to explain how I saved my game moreso than what I and others have, please, just ask. And if you want to se it in action, check out my website, I've got a beta beta out for download.

Regards.

Note1: Just to point this out, since the stupid website news isn't letting me update (Stupid AngelFire!) there is a slight glitch, and will not overwrite a previous save. This will be fixed next release.

Note2: Yes, I know there's two betas. That's because it's a beta of a beta. (Get it? No? Darn, I have such a bad sense of humor! )

Usermlsra - Causing Havoc with a Smile
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 8th Oct 2003 11:08
Ok i will have a look around.


Thanks and i may need a little more, help.....just a maybe.


Thanks

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 8th Oct 2003 20:13
Hey Usermlsra , i looked at your game and it was cool.
Could i veiw your save code please so i could study it please?

Great game

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
Rwilson
21
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 8th Oct 2003 21:22
Well, that is my save code you have posted as a snippet in your first post, up top. It's missing a little,but I'll give you a rundown on how it works.

First, the code checks for a pre-exisitng save game and ask if ou wish to overwrite it, using this code here:



How this works is that the variable fileexist stores the result of the command File Exist, which is either a 1 or 0. Then, if it equals 1, it ask if you want to delete the original file. If yes is the answer, it torches the file, if no, it goes back to the main area (The goto command).

After that, I tell it to Open To Write 1,"Save File.sav". What this does is create a file called Save File.sav, and assigns it to the file number 1. From there, you save the variables you want to save with Write Word 1,variablename, which writes a integer to file 1, based on which variable you feed it, and Write String 1,StringName, which writes a string to file 1, also based on which variable you indicate. When everythings saved, I tell it to close the file with Close File 1, which saves it all off.

Loading is basically the same thing as saving, except using the Read Commands instead of Write Commands. One thing to note, though, is the fact that you have to read it all back in the order you saved it, or you'll end up with your level as you MaxHP, your Name as your Class, and all sorts of other mix-ups! The reason why is it reads the file in the exact same order you write it, and the program doesn't distinguish between MaxHp and Level numbers.

Need any more help?

Usermlsra - Causing Havoc with a Smile
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 8th Oct 2003 21:57
Please help a little, ok say i have a character, that character has a starting health of 200, so how do i save it's current health in the game?

Could you show me, what i would need? like the INTEGER.

Thanks

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
Rwilson
21
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 9th Oct 2003 02:12
This depends upon how you go about having your current HP. If you have a variable that stores the current hp, its basically just

Write Word filenumber,VariableName

So lets say you store your current health in the varible CURRENTHP, and your save file is open to number 1, you would code:

Write Word 1,CURRENTHP


The INTEGER command is used when making UDTs (User-Defined-Types), htus it's not really connected to saving.

Usermlsra - Causing Havoc with a Smile
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 9th Oct 2003 10:38
I see, so would i aslo need the position camera as well? so it stores the camera postition?

I see what you are getting at.

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
The Lone Programmer
21
Years of Service
User Offline
Joined: 29th Jan 2003
Location: California, USA
Posted: 10th Oct 2003 02:57
Andrew,
Is your save code used with pro or classic?

If it is classic would you mind explaining what everything you did is cause I am currently trying to save and I have no clue what write string and write word is all about.

I have DBC not DBP

Thanks
Nicolas

*Current Project: Untitled RPG
*Working With: Vash the Stampede 815
*Future Number: Eleventy
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 10th Oct 2003 11:12 Edited at: 10th Oct 2003 19:35
Please look below

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 10th Oct 2003 19:33
Hi nick, i will try and help you as much as i can.
First, i use DBP not DBC but:
write string - this means this command will write the specifified string to the file. The string will be terminated in the file with the standard carriage return ASCLL characters (13)+(10). The file specified by the file number must open or the command wil fail.

Basically it will write a string into the saving, such as write string 1,string here.

Next
write word - this means it will write a word of data to the file from an interger value in the variable specified. A word represents two bytes. The file specified by the file number must open or the coomand will fail.

Basically you use write word to store the currunt things, like camera position, character poistion, energy for both character and enemy.

If you look at this code, it will give you a basic idea on what you need :


After a while it gets easier to understand, tyr starting with a very simple game, like a few objects that move and a camera, and have a small saving part, then build your way up, like i am (infact i really undersatnd)
Dont forget that there is lots of other coomands such as write long, etc...
If you need any more help, please ask and like i said, i will help you as much as i can untill you get it right

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool

Login to post a reply

Server time is: 2024-11-25 11:20:29
Your offset time is: 2024-11-25 11:20:29