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 / Writing files using write string function , Problem.

Author
Message
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 12th Jul 2008 01:37 Edited at: 12th Jul 2008 01:42
Hi ,

I try to save my level in a file with name "c:level1.txt"

I am using the write string variable.
My code is:



This will open one text file in this format

001.
001.
001.
001_

If we say every four "001." are one square each square has four "001." in the row.

How to make my file save like this.

001.001.001.001_

I don't want save the string in seperate lines.

Lets assume that, I have one map 10x10 so each square will have 10
001.001.001.001_

Each four 001. is one square.

So if I put some loop in my code I will have this.

For example



The file must be like this



As we know in basic so many years ago.
If we put the ";" charachter at the end of the line , we say
we don't want to change line.

So lets assume that the code will be like this.



And why we need to delete the file allways?
As we know many years ago , in basic , if we open the file
it overwrite its self automatically.
If we don't delete the file nothing happens.

Might this is a bug?
Or what could I do when I write one string in a file I don't change
my line.

I tried this code:



I manage to put only one square in my file with this format.

And the file was like this:



But I don't want that.

If we assume the , I want to have 200 squares in my file , the only way that place all off my string in one line was this:



So If I assume that , I want to record a file with one map level
200x200 I need to do this.



It will be very good , Lee add this option , if we place ";" charachter at the end of some string then we force the language not put the special chr$(13) charachter at the end.

Does anyone has an idea how do I not change my line when I put something in my file?

Ps , when the game will finish, I will put creadits for people who helped me to solve my problems.

Thank you very much...



http://i-access.gr/future/Banner.jpg
You are an elite hacker and try to save the cyberspace.
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 12th Jul 2008 01:45 Edited at: 12th Jul 2008 01:50
Edit:
oops I delete spamming duplicated post.

http://i-access.gr/future/Banner.jpg
You are an elite hacker and try to save the cyberspace.
Nano brain
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 12th Jul 2008 06:19 Edited at: 12th Jul 2008 06:20
Write a for loop to extend the number of boxes for you.

EX:


Let me know if you need more help.
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 12th Jul 2008 20:31 Edited at: 12th Jul 2008 20:52
I have problem , I cant understand , why this basic is not working as c and visual basic.


In traditional programming one classic programmer if he wants to
save one array like levels(1,20,20,4) in one file.
Uses the classic way.
He makes 2 loops



With this code I have this result

level1.txt


I didn't write all file because is huge.

If I increase the horizontal variable for 10 to 20

for horizontal=1 to 20

The programm crashes.

I write this code in visual basic and it works well.






Things are so simple and Darkbasic make them so complex why?

The visual basic code generete this text file:

module.txt The correct file



This is an empty level map with 50x50 empty squares.

One square has four 000. and finishes with "_"

000.000.000.000_000.000.000.000_000.000.000.000_000.000.000.000_

http://i-access.gr/future/Banner.jpg
You are an elite hacker and try to save the cyberspace.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 12th Jul 2008 21:38 Edited at: 12th Jul 2008 21:40
Try something like this. You can keep adding the coordinates to a string until all of the horizontal coordinates have been added. Then, you just write that string and go on to the next line.

This isn't a full code, it just demonstrates a concept you could try...


Nano brain
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 12th Jul 2008 23:13 Edited at: 12th Jul 2008 23:13
Sixty Squares,

That's the concept I put out above. The problem is now that the program is crashing after so long a string when trying to write it.

Takis76,

I believe it's because strings are limited to 255 characters in DB. I'm not too sure of a way around this. I'm sure it is, but by chance is the entire "001." necessary? If not, then shorten it to "0." if possible. This will allow you more space on a limited string.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 12th Jul 2008 23:55 Edited at: 12th Jul 2008 23:56
@Nano Brain: Oh whoops I should've read your post .

A way around it could be to use an array to hold the strings, each dimension of it holding 255 characters of the developing string (if it's longer than 255 characters, that is). You could then write all of the array slots to the file using the WRITE STRING command. I think that would work.

Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 13th Jul 2008 00:28 Edited at: 13th Jul 2008 00:31
This code corrected the first problem.




I manage to save my level , lets see what I do when I try to load.

I have this result: Correct result
I don't put all file here is not necessary.



I didn't use your code , but it gave me Idea.
Thank you very much , for so far , I will add you to my credits.
And you are welcome to my game testers.

Darkbasic is a very good language , but sometimes it works little
unorthodox.

In loops , in saves , in strings and in return multiple variables
from a single function , it works very unorthodox.

I will forget , everything I have learned since 1988 in Basic.

In Darkbasic this is the first time which , I tried to open files.

As we know in basic , we use ";" to avoid change lines and don't need to add many strings to one string.
In this subject , DarkBasic needs to be changed.

If you where , qbasic programmer , visual basic programmer and gwbasic programmer in the past , or if you are still a visual basic programmer today , or at least qbasic 7 programmer , you can understand what I try to say.

If believe basic is a universal language and some rules remains the same in the core.

I believe....

But I don't thing so.

Each company has it own way to create one language.
Where are the old good days of programming.

Today everything are very confused...

In past years in the age of 90s , it was very difficult to programming a game, but you where programming well , and you learn computer with correct way.

Today , is very easy to programming one game , but you are learning nothing , or with wrong way.
And in fact you are not learning computer.

In the past I programmed in only one language.

In the past I was programming in Quickbasic 4 only and I had create a lots of things (Games).

Today I am programming in c++
In DarkBasic Pro
In Visual basic
In Game studio
And countless other programming languages
And I have create nothing.

And this happend not only in programming languages it happens in other programms , as paint programms.

In past days , I was creating graphics with , Deluxe paint from Electronic arts.
And I had create a lots of things.

Today , we have a lots of difficult programms
Each newer version you need to learn everything from the beggining.

Paintshop
Photoshop
Gimp
3D Studio
3D World Studio
Gamespace and other countless programms.

In the past we used only one programm to do a lots of things.
And today we use a lots of programms make one thing.

And in the most ways , we make nothing...



http://i-access.gr/future/Banner.jpg
You are an elite hacker and try to save the cyberspace.
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 13th Jul 2008 00:52 Edited at: 13th Jul 2008 01:01
Quote: "
I believe it's because strings are limited to 255 characters in DB. I'm not too sure of a way around this. I'm sure it is, but by chance is the entire "001." necessary? If not, then shorten it to "0." if possible. This will allow you more space on a limited string
"


Nano brain ,

I cant use only 0. because with this way I will have only 9 kinds of walls.

With 000. I have 999 different kinds of wall sets in each side.
I don't know if I need to increase them to 0000. in the future.

So the adding strings will be problem.



And something else , there will be a problem , if in one game , someone needs to create one huge map 1000x1000 squares with long strings.

My example is one of the examples that will become problems in the future...

Edit:

DarkBasic have a very good function with name save array , but does not save the files with this way , saves everything in single line.

This is a good Idea , in the next version of darkbasic , Lee , add some flag to tell , if you want to change line or not.

This is just an Idea...

Edit2:

";" special charachter will be very usefull in next versions of DarkBasic Pro...

http://i-access.gr/future/Banner.jpg
You are an elite hacker and try to save the cyberspace.
Nano brain
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 13th Jul 2008 01:04 Edited at: 13th Jul 2008 01:04
My fear was you did need the "000.". There are other methods to this, but somewhat more complicated...but doable.

For example, if a string is greater than 255 characters, then place the extra characters on the next line and so forth. Truncate each line to 254 characters, if this is the case, adding a special character(something like an asterik(*)) at the end of each line that had to be truncated. This could be used to signal your map loader that the current line continues to the next line. All in all, it really would not be too hard to code. Ask for help if you need it.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Jul 2008 01:11
It sounds like the upper limit of 255 characters when writing to a file is still in place (it's a bug BTW).

I have an alternate file plug-in in my utility plug-in set that correctly handles long strings - you can use that instead. Here's a link to the help files so you can take a look at what it provides: http://www.matrix1.demon.co.uk/Matrix1Utils_Help/Matrix1Util_22_index.html

Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 13th Jul 2008 01:16
I have a lots of questions , my friend Nano Brain.

The map saved.

How to load now?
Big trouble.

How to load each square now?
I need to read for each side , four charachters (4 bytes) , and store them back to the array levels(level_number,horizontal,vertical,sides).

000. The first side needs to be stored back to the array as
Levels(level_number,horizontal,vertical,1)
000. The second side will be stored in Levels(level_number,horizontal,vertical,2)
000. The third side will be stored back to array as Levels(level_number,horizontal,vertical,3)
000_ and the last side which represents one complete square need to be stored to Levels(level_number,horizontal,vertical,4)
and incresed the horizontal by one.

Oppps , big trouble now (&^#$^%@$%^@^)

Grrrrrr....

How to make it now?

http://i-access.gr/future/Banner.jpg
You are an elite hacker and try to save the cyberspace.
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 13th Jul 2008 01:19
Eeee! Matrix Utility?
What it does?
It sounds interesting.

Could I able to save my level with one function like save array?
Could I load my file and I read a fixed size of bytes?

???

http://i-access.gr/future/Banner.jpg
You are an elite hacker and try to save the cyberspace.
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 13th Jul 2008 01:26 Edited at: 13th Jul 2008 01:34
IanM where are you?
What does this?

Shall , satisfy my programming loading level problems?




Where do I download this plugin?


Ok I download it , now how is working.

Why a programmer is suffering so much to create one game?

http://i-access.gr/future/Banner.jpg
You are an elite hacker and try to save the cyberspace.
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 13th Jul 2008 01:40 Edited at: 13th Jul 2008 01:44
Ok lets play with new toy.
Now re-writing all proccess with new commands.

Now we need to create the same file , with the same file format.
With the same sides with 000.000.000.000_ blah blah...


Edit2:

And something else I forgot.

Is there any way to encrypt my text files , because are in plain text and someone can change them and the game will be very easy for hacking.

For example in the map the door in direction 23,10 is locked , someone will open the text file , will replace the locked door with an empty square , and the adventure will ruined.



http://i-access.gr/future/Banner.jpg
You are an elite hacker and try to save the cyberspace.
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 13th Jul 2008 16:11
Hmm , I manage to load my file back to array.
This plugin is very good.

IanM you will be in my credits now and my game tester.

Can I encrypt my datafiles?

Thank you!!

http://i-access.gr/future/Banner.jpg
You are an elite hacker and try to save the cyberspace.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Jul 2008 16:42 Edited at: 13th Jul 2008 16:43
Quote: "Where do I download this plugin?"

From the link in my signature line - how do you feel about having another 650 to 700 commands available?

Quote: "Can I encrypt my datafiles?"

Encryption is something that I'm planning to add - I want it to be easy to use, but powerful and flexible (they don't go together easily as you can imagine), I want to be able to interface it in such a way to allow you to use the standard LOAD commands on them.

In all, it's a hard target I've set myself, and it'll be a long time before it appears ... if ever.

Quote: "Could I able to save my level with one function like save array?"

The LOAD ARRAY/SAVE ARRAY for UDT arrays is also something I've been thinking about, and that's much more likely to appear sometime - it's possible with my array plug-in to write something very close right now, if you don't mind mucking around with peeks/pokes.

Quote: "Could I load my file and I read a fixed size of bytes?"

Yes, but probably not in a way that's obvious. If I wanted the contents of a file in a string, I'd use the memory bank plug-in.
I'd use MAP FILE TO BANK to get the file loaded into memory, then I'd use BANK STRING$ to read the whole bank into a string.


Bank commands available here: http://www.matrix1.demon.co.uk/Matrix1Utils_Help/Matrix1Util_01_index.html

I may at some point add a few more commands to the file I/O plug-in to allow you to read/write raw strings and memory, but that's not a high priority as that's easier done using banks right now.

Nano brain
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 14th Jul 2008 09:39 Edited at: 14th Jul 2008 20:43
IanM,

Thanks for a great plugin! And thanks for helping out on this thread.

Takis76,


Go here for a possible great decryption plugin. I haven't checked it out yet. But it claims to be a heavy decryption program. I'm going to check it out tomorrow. Possibly no need for your future hard work on such a ultility IanM?[href]null[/href][href]null[/href]
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 14th Jul 2008 14:51
@Takis76: Um, couldn't you just write integers instead? That would make loading much easier, I think. Sorry if I'm being ignorant of something.

@IanM: Your plugins are the best. I'm still using your string parser .

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Jul 2008 15:08
@Nano brain,
It's a start, but I want:
- Many different encryption types
- Chaining of encryption types together (eg Serpent, followed by Twofish, followed by AES)
- The ability to add other transformations to the string (such as unzipping after decrypting)
- No writing the encrypted data to external files, even for loading objects or images

As I said - a hard target to hit, and I'm not altogether sure it's possible without changes to the DBPro runtime.

Nano brain
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 16th Jul 2008 22:09
IanM,

I had not dabbed into the encryptor, so I was not sure of what all it 'lacked'. Good luck on that target.

Login to post a reply

Server time is: 2024-11-25 21:34:58
Your offset time is: 2024-11-25 21:34:58