Hi all! I am having some problems populating an array made up of a UDT, i know this is something simple but i cant quite work out where i am going wrong so i have posted up what i think is the relevant code and if someone can steer me right to the no doubt daft mistake ill be very much appreciative.
Function SpawnFaction()
For a = 1 To 5
If Faction(a).Number = 0
Faction(a).KingName = SpawnKingName(Name$)
Faction(a).Number = a
Endif
Next a
Print Faction(1).KingName
Print Faction(1).Number
Print Faction(2).KingName
Print Faction(2).Number
Print Faction(3).KingName
Print "Test"
Wait Key
Endfunction
Function SpawnKingName(Name$)
Dim Title$(3)
Dim Fnames$(5)
Dim EndTitle$(5)
For a = 1 To 3
Read Title$(a)
Next a
For a = 1 To 5
Read Fnames$(a)
Next a
For a = 1 To 5
Read EndTitle$(a)
Next a
KingTitle$ = Title$(RND(2) + 1)
KingFName$ = Fnames$(RND(4) + 1)
KingEndTitle$ = EndTitle$(RND(4) + 1)
Name$ = KingTitle$ + " " + KingFName$ + " " + KingEndTitle$
DATA "Sir", "Lord", "King"
DATA "John", "David", "Somarl", "Enerzeal", "Richard"
DATA "The Coward", "The Bastard", "The Depraved", "The Brave", "The Lionheart"
Endfunction Name$
It seems to be populating the first part of the array with a name (which is what i want) Faction(1).Kingname is fine but what works for that does not work for the rest as if it doesnt cycle through the others. So that little print bit at the end writes a full name correctly, then the correct faction number (which would be 1 at first) then a blank space therefore no name, then the right faction number again which is 2, then another blank space where faction 3's name is. So that peice of code is definately going through all the for loop and adding a new number to each of the faction numbers and it prints fine, its just it only seems to create 1 name and pop it in faction 1's name slot and then doesnt bother going through that function again.
It may be something to do with dimming the arrays over and over again every time it calls the name function, i will try this once and see how it works.
If i need to post more code i will.
Thanks.
*Edit: I knew writing it out here would be the only way i could figure it out. As usual i spend all my resources thinking how to solve a problem then only come up with the solution almost immediately after i have posted a stupid question. It was as i suspected that i am trying to remake the arrays everytime it calls that function and it doesnt like that so i moved it out of the way and it works a charm.