How to use DATA command in Blitz Max?

BlitzMax Forums/BlitzMax Beginners Area/How to use DATA command in Blitz Max?

AD(Posted 2006) [#1]
I'm moving from Blitz Basic to Blitz Max and would like to upgrade my DATA commands, but I don't know how to do it.

On the Blitz Wiki it shows "DefData" and "ReadData" but there aren't any examples.

Ideally, I'd like it to be oo-orientated in this example;

Global player_list:TList=CreateList() 'To Store all the players

Type player
	Field name$

	Function create(_name$)
		p:player 	= New player
		p.name$		= _name$
		ListAddLast player_list, p
	End Function	
End Type

' Example data, this won't work in Blitz Max;
.lbl_names
Data "Smith"
Data "John"
Data "Bob"
Data "end" ' This is a marker saying its reached the end of all the names



klepto2(Posted 2006) [#2]
lobal player_list:TList=CreateList() 'To Store all the players

Type player
	Field name$

	Function create(_name$)
		Local p:player 	= New player
		      p.name$	= _name$
		ListAddLast player_list, p
	End Function	
End Type


RestoreData lbl_names

Repeat
	Local Name:String 
	ReadData name
	If name = "end" Then Exit
	Player.Create(name)
Forever

For Local P:Player = EachIn Player_List
	Print p.name
Next

' Example data, this won't work in Blitz Max;
#lbl_names
DefData "Smith"
DefData "John"
DefData "Bob"
DefData "end" ' This is a marker saying its reached the end of all the names


This should work.
Info:
Data statement has changed to DefData
the label indicator has changed to #


AD(Posted 2006) [#3]
Many thanks for your help!


AD(Posted 2006) [#4]
I keep getting an error;

"Unhandled exception: attempt to access field or method of null object" on this line;

ListAddLast player_list, p


It doesn't seem to like it when there is NULL data.


degac(Posted 2006) [#5]
you need to declare GLOBAL the list player_list


Grisu(Posted 2006) [#6]
Why make this so complicated.
You can always "incbin" a text file with all data strings and read them out from there?


AD(Posted 2006) [#7]
what is a incbin? I'm not aware of this feature? I just wanted to make it easy for me (or other developers in the future) to be able to change certain charactersitcs of the game without having to do big huge rewrites.

I'm interested in the incbin -- what is it?


AD(Posted 2006) [#8]
I got the example that klepto2 working, but I am still interersted in incbin... I've done some searching but there is no example of how to use it from start to finish.


degac(Posted 2006) [#9]

Rem
IncBin embeds an external data file in a BlitzMax program that can
then be read using the "incbin::" device name.
End Rem

' code snippet from demos/firepaint/firepaint.bmx

Incbin "stars.png"

Local stars=LoadImage( "incbin::stars.png" )



With INCBIN command you force to 'include' in your program the data you want (image, sound, generic data...) without need to load them from 'extern' of the program itself.
So you can send ONLY the .exe WITHOUT the other datas (images, sounds,...)
It's very useful.


AD(Posted 2006) [#10]
Many thanks - I appreciate it!