Ok, here's my latest cut. All systems go!
Remstart
Project: Population Maker Ver 3
Created: 12/12/2010
By: Burningfeetman
Credits:
Hats Off to Agent & Lucas Tiridath for helping me with this code
Notes:
* Although input via CSV file is possible, it is an over complicated solution for the simple input of first and last names.
To Do:
* Boy and Girl names will have to be sourced from two different input txt files.
* Tidy up input files and code:
* Name/Male.txt, Name/Female.txt, Name/Family.txt
* Add ID tag for final population
* Add control regarding male to female ratio
* Add age along with age controls
* Add control to alphabatise the output and re-assign sorted ID tag.
* Export Final Population using Matrix1 Utilities, User Define Type Expor - SAVE ARRAY TO DATAFILE Array(), Datafile Id
* Exported list can then be imported and used in future games.
Remend
#Constant funcdebug 1 `Function Debug - Simply change between 0 or 1 to toggle debug mode.
RANDOMIZE TIMER()
Type tPopulationStats `WIP
tag as Integer
first_name as String
last_name as String
age as byte
sex as boolean
Endtype
Databump as Integer
UniqueName as Integer = 0
DesiredPopulation as Integer
Dim DataRandom(0) as Integer
Dim FirstNamePool(0) as String
Dim LastNamePool(0) as String
Dim CombinedNamePool(0,0) as String
Dim PopulationSelect(0) as tPopulationStats `WIP
Print "Welcome to BFM's people maker!"
Print ""
Print "A List of First Names"
Print ""
Databump = 1
Open to Read 1, "inputdata/firstname.txt"
While not File End (1)
Array Insert At Bottom FirstNamePool()
Read String 1, FirstNamePool(Databump)
Print "First name: " ; FirstNamePool(Databump); ", " ; Array Count(FirstNamePool()) ; ", " ; Databump
Inc Databump
ENDWHILE
Close File 1
Waitasec(funcdebug)
Print "A List of Last Names"
Databump = 1
Open to Read 1, "inputdata/lastname.txt"
While not File End (1)
Array Insert At Bottom LastNamePool()
Read String 1, LastNamePool(Databump)
Print "last name: " ; LastNamePool(Databump) ; ", "; Array Count(LastNamePool()); ", " ; Databump
Inc Databump
ENDWHILE
Close File 1
UniqueName = Array Count(FirstNamePool()) * Array Count(LastNamePool())
Print Array Count(FirstNamePool()) ; " * " ; Array Count(LastNamePool()) ;" = " ; UniqueName ; " unique names"
Undim CombinedNamePool()
Dim CombinedNamePool(1,UniqueName) as String
Waitasec(funcdebug)
Databump = 1
FOR x = 1 to ARRAY COUNT(LastNamePool())
FOR y = 1 to ARRAY COUNT(FirstNamePool())
combinednamepool(0, Databump) = FirstNamePool(y)
combinednamepool(1, Databump) = LastNamePool(x)
INC Databump
NEXT y
NEXT x
For RollCall = 0 to UniqueName
Print CombinedNamePool(0, RollCall) ; " " ; CombinedNamePool(1, RollCall) ; " " ; RollCall
Next RollCall
Print "End list of " ; UniqueName ; " unique Full Names. Begining population attribute sequence"
Waitasec(funcdebug) : CLS
Input "Please enter the desired population. (Maximum of " ; UniqueName ; ") ", DesiredPopulation
UnDim PopulationSelect()
Dim PopulationSelect(DesiredPopulation) as tPopulationStats
Rem - Scramble The Unique Name Array - Only need to scramble the amount of required names,
For Order = 1 to DesiredPopulation
swap = rnd(UniqueName-1) + 1
temp$ = CombinedNamePool(0,Order)
CombinedNamePool(0,Order) = CombinedNamePool(0,swap)
CombinedNamePool(0,swap) = temp$
temp$ = CombinedNamePool(1,Order)
CombinedNamePool(1,Order) = CombinedNamePool(1,swap)
CombinedNamePool(1,swap) = temp$
Next Order
For RollCall = 1 to DesiredPopulation
Print CombinedNamePool(0,RollCall) ; " " ; CombinedNamePool(1,RollCall)
Next RollCall
Waitasec(1)
End
Function Waitasec(X)
Print ""
If X = 0
Exitfunction
ENDIF
Nice Wait 500
Nice Wait Key
Endfunction
I'm going to spend more time on working out how to import CSV data OR txt file data. Sooner or later I'll be pumping some data that I've got stored in CSV format into my games, so it's best I start figuring that out sooner than later. Will hopefully have this CSV import code sorted by the end of this week.
EDIT: And thanks a few hours spent on the forums this morning, I do believe I've cracked it. Here's my first attempt, I was surprised it worked first go too!!
Databump = 1
Open to Read 1, "inputdata/Name Spreadsheet.csv"
While not File End (1)
Array Insert At Bottom FirstNamePool()
Read String 1, Temp
Split Csv String Temp
Print Split Count()
FirstNamePool(Databump) = Get Split Word$(1)
Print "First name: " ; FirstNamePool(Databump); ", " ; Array Count(FirstNamePool()) ; ", " ; Databump
Inc Databump
ENDWHILE
Close File 1
It'll need some refinement here or there. But it works, and now I can code up all my data for my games in Google Docs, then export the data to a CSV and it inserts straight into my game!
This is brilliant... It's such a dynamic way of coding!
EDIT: Now, I need to have a serious think on how to move forward with my projects now that I have an understanding these tools.
ANOTHER EDIT LOLCAT: In further thinking, I think it's best to keep data such as a list of first names, and a list of last names separate in two txt files, rather than bundled together in a CSV file. Problems encountered say, if I have 300 first names, and only 50 last names. Problems that can be avoided by not processing the data in CSV format, but sticking with two separate txt files.
Other data is perfect to be managed and then input via CSV, but not names and not for this system. So with that, I'll tidy up my code and post a final cut for this weekend.