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 Discussion / Saving - Done! Loading - Help!

Author
Message
Stora tomtefar
21
Years of Service
User Offline
Joined: 15th Mar 2005
Location: Göteborg, Sweden
Posted: 25th Jan 2006 21:28
Okej! Here's the thing; I've created a level-editor for my game in DarkBasic Classic, and I've understood how to save one objects position, and basicly every value and string, to a text file using the "open to write"-command.
The system this is based upon is that one tile, which you're moving, are the one whos X and Z coordinates are saved when pressing space. Then a static object is created on that current position, after which you're free to move the tile again. This return these values:

1 - the number of tiles used in the level
0 - Xposition
0 - Zposition
tile$
2
0
298.365

These number are stored after these sections of code has done their magic:
If spacekey()=1 then inc makestatictile#,1
If makestatictile#=1
make static object 1
Inc numberoftiles#,1
Write float 1,numberoftiles#
write float 1,Object position X(1)
write float 1,Object position Z(1)
Endif
If spacekey()=0 then makestatictile#=0


However... I want to be able to load these pieces ov variables into the game itself, but I don't know how. Is it possible to select precisely which line DB should read from and save this in a value several time in a "next x"-loop?

The "Read float"-command doesn't appear to work either since it returns the value of 6, plus some decimals, when it should be returing a one. Any ideas how I should do, or any tipes of other techniuqes? That would make me so happy!

"Even though I'm ugly, I'm extreamly sexy!"
AndLabs
21
Years of Service
User Offline
Joined: 7th Dec 2004
Location:
Posted: 25th Jan 2006 23:25
You'll need to read and write a single line, then use the VAL() command to return the float values.

For the Software You Want, AMPERSAND LABORATORIES is the place!

Stora tomtefar
21
Years of Service
User Offline
Joined: 15th Mar 2005
Location: Göteborg, Sweden
Posted: 26th Jan 2006 16:14
So I can't use multiple lines which I have done?
How should I do then? Save every value in different files? Naa...

The explanation provided by DarkBasic doesn't exactly make me bright:

"This command will return an integer number of the string provided by converting the string to a numerical form."

"Even though I'm ugly, I'm extreamly sexy!"
Baggers
22
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 26th Jan 2006 17:30 Edited at: 26th Jan 2006 17:31
Heres a wee saving/loading tutorial I just knocked up. I hope it will answer a few questions. If not just say and I'll have another go !


Stora tomtefar
21
Years of Service
User Offline
Joined: 15th Mar 2005
Location: Göteborg, Sweden
Posted: 26th Jan 2006 18:15 Edited at: 26th Jan 2006 20:30
Thanks Baggers! That got me more wise. However, I still got some questions.

When I saved the values, is it possible to load them the same way in another program (which is the game itself)

And what is the differens between word, floats and the other input commands? The only thing I've found that really seperates them is that strings saves text, but that's all. What other differenses are there?

*EDIT*
One other thing! is it possible to, by using a "NEXT"-loop, change the name of strings-values, float-values, etc etc?

"Even though I'm ugly, I'm extreamly sexy!"
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 27th Jan 2006 00:20
You can load values in another program.


This example shows you how Strings can be altered....

Reset$ = "Value"
For n = 1 to 10

Counter$ = Reset$
Counter$ = Counter$ + " " + Str$(n)
Print Counter$

Next n

Baggers
22
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 27th Jan 2006 07:22
Quote: "When I saved the values, is it possible to load them the same way in another program (which is the game itself)"

Yep, easy as pie, I'll make an example after work today.

Quote: "And what is the differens between word, floats and the other input commands? The only thing I've found that really seperates them is that strings saves text, but that's all. What other differenses are there?"

I'll also cover this tonight...have a peek in your user manual it explain variable types quite well.

Quote: "One other thing! is it possible to, by using a "NEXT"-loop, change the name of strings-values, float-values, etc etc?"

If I'm understanding you correctly then yes....I'll write a wee example of this aswell.

So yeah basically later I'll be back...sorry for the wait. I'm sure a good few others will explain aswell.

Stora tomtefar
21
Years of Service
User Offline
Joined: 15th Mar 2005
Location: Göteborg, Sweden
Posted: 27th Jan 2006 14:53
Goddie!

If tried to rename the strings your way, Pincho Paxton, and it worked perfectly! Thanks! I also figured out how to load the strings using the same " + Str$"-command.

Baggers, there is no need to write the first and last example, but ut would be very noce of you if you, or anyone else who feel like it's your chance to brag, would explaing what the difference between strings, floats, longs, etc is.

(I just realised how cosy and helpfull this forum really is... That nice! )

"Even though I'm ugly, I'm extreamly sexy!"
Baggers
22
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 27th Jan 2006 17:01
Hokay so lets have a look at the data types…

---
Integer: This is any whole number between: –2,147,483,648 and 2,147,483,647
An example of integer use would be

A=10
Print a

---

Float: A float can store any number between -3.4E 38 (7 digits) and +3.4E 38 (7 digits)
The difference between integers and floats is that floats can store decimals.
We use a hash simple to tell the computer that the variable is a float.
e.g.

a#=10.5
print a#

---

String: A string variable is one that holds text. We use a dollar symbol to tell the computer the variable is a string.
e.g.

a$=”Hello”
print a$

Notice how we put the words in “speech marks” this is important as it shows you are putting in text not numbers or another variable.

---------------------------------





Theres some neat simple things we can do with variables such as adding them

A=5
B=6
C=A+B
Print C

We can do this with floats aswell

A#=5.45
B#=3.33
C#=A#+B#

We can also use other symbols:

We can minus with the ‘-‘ symbol
We can divide with the ‘/’ symbol
We can multiply with the ‘*’ symbol

We can also add strings together
e.g.

A$=”Hello “
B$=“Fred”
C$=A$+B$
Print C$

We will see it prints out “Hello Fred” as it has joined the strings together…however it must be noted that you can only add strings together the other symbols don’t work with it.

As you know there are also other some data types I’ve listed a few below.

BOOLEAN Range : 0 to 1
BYTE Range : 0 to 255
WORD Range : 0 to 65535
DWORD Range : 0 to 4,294,967,295



Well hope that helps a bit mate….also hope it wasn’t too patronising. I wasn’t sure exactly how much I needed to explain.
Anything else you need to know ?

Stora tomtefar
21
Years of Service
User Offline
Joined: 15th Mar 2005
Location: Göteborg, Sweden
Posted: 27th Jan 2006 18:30
I've got no more questions about the different types of variables, no. Even though I didn't get everything, I'm sure I'll figure it out when I use them by triyng and faling. Thanks!

Another problem I got now, however, is this one.

I used the method Pincho Paxton mentioned to load the values the my strings stored. The code I'm using for that event looks like this:



It isn't exectly like he wrote it should be, I know, but I've tried various ways to load them, but the program keeps giving me the error messege "Runtime Error at line 15. Severe Exception!", and I don't know what to do about it.

"Even though I'm ugly, I'm extreamly sexy!"
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 27th Jan 2006 22:52
It's because you're doing this:


When you use "read string" it only wants a string... not an integer converted to a string (the way you have it does work in Pro but not Classic).

I'm not sure why x is there but it should be something like this:


Also this should be different:


The way that's written if x=20 and tileX$="70" the strings are combined into "2070".

You need to do something like this instead:


The above code snip would be 90 (that snip is what should be in "position object").


Baggers
22
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 28th Jan 2006 12:16
Just as a side note I have had problems using this method read string 1,str$(x)+tileX$ in DBP aswell normally the safest way to do the above task is:


It should be noted that i havnt tried this in classic as I only have pro now.
Hope its accurate and helpful though.

Stora tomtefar
21
Years of Service
User Offline
Joined: 15th Mar 2005
Location: Göteborg, Sweden
Posted: 28th Jan 2006 19:14
Well, I got everything working now. The way I finaly managed to bring it all together was by using this code:



The reasong I wanted the strings to have the X in itself was because I wanted every object to have their own string, but that didn't worked out, so I used this method which is woring like a charm!

But...
I tried to save the program as a "stand alone executable". everytime I want to place make a tile for the level, the program crashes, along with the message "DragStrafer.exe has run into a problem and must be closed", or whatever it's says in the English XP
The code that's in use right before the program crashes is still this one:



Do you have any thoughts about why this program keep crashin? Personally I think it may have something to do with the creation of the static objects, but how and why is something I don't know...

(I'm including a, what I hope is to be an executable version of the program so you can see what the error is.)

"Even though I'm ugly, I'm extreamly sexy!"
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 29th Jan 2006 00:03
Quote: "Just as a side note I have had problems using this method read string 1,str$(x)+tileX$ in DBP aswell normally the safest way to do the above task is:"


It looked like in Pro it was just defining "x" and ignoring "tileX$".

Quote: "temp$=str$(x)+tileX$
read string 1,temp$

It should be noted that i havnt tried this in classic as I only have pro now.
Hope its accurate and helpful though.
"


That should just define "temp$" then re-define it whatever string it takes from the file. Writing would be different though.


Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 29th Jan 2006 00:11
Quote: "Do you have any thoughts about why this program keep crashin? Personally I think it may have something to do with the creation of the static objects, but how and why is something I don't know..."


Maybe it's not working right because you use the same object number over and over again... i'm not sure though.




Stora tomtefar
21
Years of Service
User Offline
Joined: 15th Mar 2005
Location: Göteborg, Sweden
Posted: 29th Jan 2006 16:19
Quote: "Maybe it's not working right because you use the same object number over and over again... i'm not sure though."


It does work if I run it within DarkBasic... Odd...

Do you think it'll work if I create a new tile after every tile I made a static out of?

I can't try it now since I'm not at the right comuter, you see.

"Even though I'm ugly, I'm extreamly sexy!"

Login to post a reply

Server time is: 2026-07-07 11:21:06
Your offset time is: 2026-07-07 11:21:06