Making txts you can work with in notepad

Blitz3D Forums/Blitz3D Beginners Area/Making txts you can work with in notepad

fox95871(Posted 2009) [#1]
I played a Blitz game one time that had some txt files in its program folder for what looked like user variables, but it had very readable words and numbers instead of symbols. I'm currently studying the file commands, but so far I can't seem to make anything but txts that are all symbols when you open them in Notepad. I want some aspects of my engine like character dialogs to be editable outside the engine since making some kind of word processor applet for my engine is definitely not something I want to do! Can someone please explain how I can make Notepad editable txts that hold variables?

Here's part of one of the txts in the game I mentioned:



Ross C(Posted 2009) [#2]
don't use .txts. Just make your own file format.

Create a file called yourfile.dat in blitz, and save out all the data you want in it, via writeline usually. You can then open this in notepad and edit it. Not sure if saving will cause it to save as a .txt though.


PowerPC603(Posted 2009) [#3]
Try this:

Source-code:
Graphics 800, 600, 0, 2

; Setup global vars
Global ScreenWidth, ScreenHeight, ScreenDepth, ScreenMode
Global ScaleableWindow

; Open the file
Global File = ReadFile("Test.txt")
; Keep reading until End Of File has been reached
While Not Eof(File)
	Local LineFromFile$

	; Read an entire line from the file
	LineFromFile$ = ReadLine$(File)

	; Check the parameter to be read from the file
	Select LineFromFile$
		Case "[screen settings]"
			ScreenWidth = Int(ReadParameter$())
			ScreenHeight = Int(ReadParameter$())
			ScreenDepth = Int(ReadParameter$())
			TempMode$ = ReadParameter$()
			If TempMode$ = "windowed" Then ScreenMode = 2
			If TempMode$ = "full" Then ScreenMode = 1

		Case "[scaleable window]"
			ScaleableWindow = Int(ReadParameter$())
	End Select
Wend
; Close the file
CloseFile File


If ScreenMode = 1 Then
	Print "FullScreen: " + ScreenWidth + "x" + ScreenHeight + "x" + ScreenDepth
Else
	Print "Windowed: " + ScreenWidth + "x" + ScreenHeight + "x" + ScreenDepth
EndIf

If ScaleableWindow = 1 Then
	Print "Scaleable Window: yes"
Else
	Print "Scaleable Window: no"
EndIf

WaitKey()
End




Function ReadParameter$()
	Local LineFromFile$
	Local Pos

	; Read an entire line from the file
	LineFromFile$ = ReadLine$(File)
	; Search for the ;
	Pos = Instr(LineFromFile$, ";")

	; If the ; has been found
	If Pos > 0 Then
		Return Mid$(LineFromFile$, 1, Pos-1)
	EndIf

	Return ""
End Function


Textfile (save as Test.txt in the same directory):
[screen settings]
1024; Screen Width
768; Screen Height
32; Screen Bit Depth 16 or 32
full; full or windowed

[scaleable window]
0; 0=no  1=yes


This example reads the first two parameters (ScreenSize and ScaleableWindow), you can expand it further by adding all parameters to the Select Case block.

Run this, the program will print the values to your screen.
Then change something in the textfile (Test.txt needs to be in the same dir) and see the results.


Warner(Posted 2009) [#4]
Ow .. nevermind.


Zethrax(Posted 2009) [#5]
To save text data; open a file for writing with a file extension that your system will recognize as a text file, and then use the WriteLine command to write out string data to the file. Note that when you use WriteLine, it automatically adds end-of-line characters to the end of the line of text you are writing out. Check the online docs for the WriteLine command for more information.

Blitz will automatically write out numeric data as text, and can parse textual representations of numbers back in as numeric data, so you don't need to do anything special to convert numbers to and from text.

The data that WriteLine writes out is just text data, so you will need to organize it into a format that your program can interpret. This can be as simple as writing and reading the data in the proper line sequence. If you want to be able to write and read values out of sequence, then you can look at an ini data format that uses name=value style organization. For more complex arrangements of data, you can look at using some sort of custom script file format.

For some examples, try looking through the code archives I've linked to below.

http://www.blitzbasic.com/codearcs/codearcs.php?cat=8&order=&asc=&lang_id=1


Nate the Great(Posted 2009) [#6]
use writeline!

unless you want to figure out the .txt file format and write in hex???


fox95871(Posted 2009) [#7]
Great, so many replies! I'm at an internet cafe right now so I can't read all this, but I'm throwing it on my usb and I'll look at it tonight. Should be fun. Thanks, and feel free to post more if there's any more that can be said.


jfk EO-11110(Posted 2009) [#8]
"figure out the .txt file format" ??

As far as I know the txt format is really only ascii text. There may be diffrences with the linefeed, for example UNIX is using diffrent linefeeds. As the others said, when you use WriteLine then it will be perfectly readable by Notepad.


fox95871(Posted 2009) [#9]
Got it!

Copy this to a txt file and name it save.txt


Then run this in the same location


You can then edit the text in the dialog window by simply editing the txt file! Thanks so much to everyone for the help, and sorry for the suggestions I didn't use.