How to use DATA command in Blitz Max?

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

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


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 #

Many thanks for your help!

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.

you need to declare GLOBAL the list player_list

Why make this so complicated.
You can always "incbin" a text file with all data strings and read them out from there?

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?

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.


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.

Many thanks - I appreciate it!