Using Data statements?

Monkey Forums/Monkey Programming/Using Data statements?

zardon(Posted 2013) [#1]
I remember in the old basic you could you use DATA statements for basic data, I'm wanting to read in 30 items into an array, but I do not want to manually write them.

ie:
Data "Hotel", 1
Data "Motel", 2
etc...

I tried doing a search for data, but couldn't find a replacement for Data.

I guess I could read from a JSON file, but I've never done this with Monkey


Goodlookinguy(Posted 2013) [#2]
I know nothing of the Data function, but you may want to look into something like this http://www.monkeycoder.co.nz/Community/posts.php?topic=1037 or http://www.monkeycoder.co.nz/Community/posts.php?topic=3077


AdamRedwoods(Posted 2013) [#3]
"Data" was good because it was packed tight in memory.

Now if you want that, you'd have to create a JSON to DataBuffer (or any parser) routine. Not trivial, but can be done. Also note: DataBuffer class now has PeekString and PokeString. Pretty nice.


zardon(Posted 2013) [#4]
I opted to choose JSON but couldn't get it to work.

I only need to add 30 items to an array. So I am trying this;

Global propertyCards[] ' Array
propertyCards[].add( New fsCard("Cardboard box",1) )	
propertyCards.add( New fsCard("Outhouse", 2) )


But neither [].add or .add work

I'm wanting to add items to an array without using indexes.


zardon(Posted 2013) [#5]
I've opted to use Lists now rather than the array as I couldn't get it to work

Global propertyCards:List <fsProperty>
propertyCards.AddLast( New fsProperty("Cardboard box",1) )	



Midimaster(Posted 2013) [#6]
You defined propertyCards as a list type, but did you forget to create a first instance?

Global propertyCards:List<fsProperty> = New List<fsProperty>
...	



zardon(Posted 2013) [#7]
I'm still very new to MonkeyCoder and this is like my first real attempt at coding anything with the language, but thanks for the heads-up. Making mistakes is all part of learning.


Markus(Posted 2013) [#8]
maybe are data commands not there because you can use this or files (plain text file).
Local scores:Int[]=[10,20,30]
Local text:String[]=["Hello","There","World"]