Using Data statements?
Monkey Forums/Monkey Programming/Using Data statements?
| ||
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 |
| ||
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 |
| ||
"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. |
| ||
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. |
| ||
I've opted to use Lists now rather than the array as I couldn't get it to workGlobal propertyCards:List <fsProperty> propertyCards.AddLast( New fsProperty("Cardboard box",1) ) |
| ||
You defined propertyCards as a list type, but did you forget to create a first instance?Global propertyCards:List<fsProperty> = New List<fsProperty> ... |
| ||
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. |
| ||
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"] |