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.

DarkBASIC Professional Discussion / save or load types, can it be done?

Author
Message
Daniel wright 2311
User Banned
Posted: 26th Aug 2010 09:12
ok, so I want to know if my code can be done difrently, as you can see in my code im saving all my data, well is there a way to put my data in a type then just save and load the type with real values. or is there a better way to change my code in a dim array then save the array.code bellow, thanks




Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Aug 2010 09:38
Yes, with IanMs Matrix 1 Utilities Plugin you can save a User Defined Type with just using his SAVE ARRAY TO DATAFILE command and load that same information with LOAD ARRAY FROM DATAFILE. All you do is define the UDT like you normally would, fill the array, and save it.

If you don't already have IanMs Matrix 1 Utilities Plugin where the heck have you been?!

Here's the link: http://forum.thegamecreators.com/?m=forum_view&t=96084&b=7

Daniel wright 2311
User Banned
Posted: 26th Aug 2010 09:40
Quote: "heck have you been?!"


lol, thanks, ill check it out

Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 26th Aug 2010 11:04
On another note; all of this code is totally superfluous:


A spade is a spade, telling it what it is doesn't change a thing.



DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 26th Aug 2010 16:49
Quote "If you don't already have IanMs Matrix 1 Utilities Plugin where the heck have you been?!"
Lol I don't have them but have used them in the past. They are good, as are a few plug ins out there, but I avoid using plug ins of late to save upgrade issues. Of course if I had a project that needed it I would use it then

http://s6.bitefight.org/c.php?uid=103081
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Aug 2010 18:39
Quote: "Lol I don't have them but have used them in the past. They are good, as are a few plug ins out there, but I avoid using plug ins of late to save upgrade issues. Of course if I had a project that needed it I would use it then "


I use a lot of IanMs commands for most of my projects.

I really love the file commands and some classics like MID$ that bring back the original Basic version of MID$. I was shocked when I found out Darkbasic would only extract one character with MID$. I ended up making a function to make my own MID$ command (as we all did probably) till IanM brought out his version.

Daniel wright 2311
User Banned
Posted: 26th Aug 2010 19:04
Quote: "A spade is a spade, telling it what it is doesn't change a thing"


yes it does if I want the states to change as i load back in. spade can =1 but when i load back in it will always =0 if I do not tell it what it =s.

Your signature has been erased by a mod please reduce it to 600 x 120.
James H
19
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 26th Aug 2010 20:05
Er you seem to have missed the point Daniel...the code Scraggle has pointed out is useless - you might as well have wrote 0=0 over and over. If you wrote game1percent=0, coloff1=1 etc then it would be of some use as you would be using those values as default values by resetting them for each variable when you "load back in"(assuming you mean you use a label and goto command). As it stands variables default values are always 0 - if they were declared as local variables within a specific nested loop and then you use the goto command to jump outside that nested loop the variables are no longer usable for the values they had as they remain tied locally to that nest; they can be used again but will initially hold a default value again(0)
Daniel wright 2311
User Banned
Posted: 26th Aug 2010 20:15
@James H

I beleve you miss my point my friend, when I take out that part and i save my games all the stats are 0, so when i do something to change a state to 1 like open a locker in game, then openlocker=1
then if i save it it will save that open locker=1, then when i load it in it will always=0 unless I tell it to = what was loaded in. see what is in memory is not changed unless i call it to be changed from what was saved.How do I know this? Like i said I took out that part in the load and all my states =0 and nothing was saved. unless im doing it wrong and if this is so please tell me a better way and I will try it out.thanks



Your signature has been erased by a mod please reduce it to 600 x 120.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th Aug 2010 20:27
Did you declare all your variables prior to entering the main code block where you load/save? DBP has automatic variable declaration which could cause problems if you don't declare them first.

The fastest code is the code never written.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Aug 2010 20:30
@ Daniel

Just jumping in on your arguments, your code basically does the following:

you set a variable:

a=2

you write that variable to a file:

open to write 1,"yeah.bla"
write word 1,a
close file 1


Then, later on you read in that variable from the file into the variable "a"

open to read 1,"yeah.bla"
read word 1,a
close file 1


And then you tell the variable "a" that it is equal "a"?

a=a

Why?

TheComet

Daniel wright 2311
User Banned
Posted: 26th Aug 2010 20:31
@Hawkblood

do you mean like at the top of my code

openlocker=0
dostuff=0
Amisostuppidthatididnotgetitthefirsttime=1

if this is what you mean then no, ill do it now though.

Your signature has been erased by a mod please reduce it to 600 x 120.
Daniel wright 2311
User Banned
Posted: 26th Aug 2010 20:33 Edited at: 26th Aug 2010 20:34
@TheComet

becouse its not saving my states unless i do it like this.also This is the main reason i posted this thread is to find out if im doing it right at all, but it does save and load the way im doing it.

Your signature has been erased by a mod please reduce it to 600 x 120.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th Aug 2010 20:34
No. Like this:
global OpenLocker as byte
OpenLocker=0 `the initial state
global DoStuff as integer
DoStuff=0 `the initial state
global Amisostuppidthatididnotgetitthefirsttime as DWORD
Amisostuppidthatididnotgetitthefirsttime=1 `a true statement LOL...

The fastest code is the code never written.
Daniel wright 2311
User Banned
Posted: 26th Aug 2010 20:36
Quote: "Amisostuppidthatididnotgetitthefirsttime=1 `a true statement LOL..."


I know right, no im not doing this, i will set it up though, It will be hard to figure out what is what like this here confuses me.

global OpenLocker as byte

Your signature has been erased by a mod please reduce it to 600 x 120.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th Aug 2010 20:40
Most variables in your game should be declared as 'global' BEFORE they are used in your program. Make a function that does like this:
function SetGlobals()
global var1 as float
global var2 as integer
......
endfunction

Then call that function at the beginning of your program. Remember, don't do any 3D objects here unless you are doing it after changing your display mode-- simple variables are fine to do before display mode, just not 3D objects.

The fastest code is the code never written.
Daniel wright 2311
User Banned
Posted: 26th Aug 2010 20:43
ok, i see it now, setting them all to global will fix it, well i do know all of them are integers with number values, all my floats are just postitions of my camera and objects. so it should be easy.

Your signature has been erased by a mod please reduce it to 600 x 120.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th Aug 2010 20:45
Because I haven't seen all of your code, I can't guarantee it will work, but it's a start. It's good practice to declare your variables before use....

Let me know if it works or not.

The fastest code is the code never written.
Daniel wright 2311
User Banned
Posted: 26th Aug 2010 20:59
ok, so i put this in here and took away all the stuff=stuff aND IT WORKS.THANKS





Your signature has been erased by a mod please reduce it to 600 x 120.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th Aug 2010 21:13
I have had problems with declaring variables like this:
global MyVar1 as integer =1
Keep in mind that all variable declarations with 'as' initialize as '0' (or so I've seen). If you want to be sure that the variable has any value other than '0', you should do this:
global MyVar1 as integer
MyVar1=1

I may have been smokin something when I had that problem, but the latter is the way I do them exclusively.

The fastest code is the code never written.
Daniel wright 2311
User Banned
Posted: 26th Aug 2010 21:18
WELL, OK, I do have one more question for you? How should i declare this code here as they all hols a value and change all the time.



Your signature has been erased by a mod please reduce it to 600 x 120.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th Aug 2010 21:26
'fogvalue' should be one of your globals. Your last line might be better written as:

You could also make this a little smaller like:


I think this is what you were asking me....

The fastest code is the code never written.
Daniel wright 2311
User Banned
Posted: 26th Aug 2010 21:31
yes it was, thanks, Im trully starting to understand how to declair and why, thanks so much for your help.

Your signature has been erased by a mod please reduce it to 600 x 120.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th Aug 2010 21:38
No problem; that's what this forum is for. I'm glad to help.

The fastest code is the code never written.

Login to post a reply

Server time is: 2026-07-23 12:10:31
Your offset time is: 2026-07-23 12:10:31