If i want to make seperate counters for a UDT array, like for example
Type FactionType
Number ` What number the faction is
SpawnTime ` Set to 0 at first, every second it gets increased
EndType
This works fine once i add a time into it that sets this up to seconds and it will show me how many seconds whatever one of the 6 factions that exist were started at. At first they are all started together so they should all read the same and they do.
For a = 1 To MaxFactions (a constant set to 6)
Print "Faction ", Faction(a).Number, " spawn time ", Faction(a).SpawnTime
Next a
Works a charm.
Now if i want to add a little random decision making to them i would want them to make decisions every 5 - 8 seconds or so.
Thats each different faction to pick a random number, at a random time between 5 - 8 seconds.
I have tried so many different variations of this and none have worked.
If i try
For a = 1 To MaxFactions
DecisionCounter = RND (5) + 3
Faction(a).DecisionCounter = DecisionCounter
EndIf
Next a
This will add a different number of seconds to each of the factions in which to make a decision. But actually getting it to check through how long the seconds have passed since then either dont work or only work once because i cant reset it to a straightforward number that allows it to be reset properly.
For a = 1 to MaxFactions
If Faction(a).STime > Faction(a).DecisionCounter ` This is not right
If Faction(a).Tactic = 1 ` Defensive
Decision = RND(99) + 1 ` All factions are getting the same decision number
even though it shouldnt even be cycling through the ones that dont have 1 for their tactic,
but i dont want all the 1's getting the same number either
way so its double broke here
If Decision > 0 AND Decision < 21 ` 20% Chance of building a tower
If Faction(a).MaxTowers < 5 AND Faction(a).Money > 600 ` If it has less than 5 towers, maximum allowed. And at least 600 coins
Inc Faction(a).MaxTowers
Dec Faction(a).Money, 500 ` Cost is 500 Coins
Faction(a).Latest = "Built a defensive tower."
EndIf
EndIf
If Decision > 20 AND Decision < 31 ` 10% of building a knight
If Faction(a).MaxKnights < 201 AND Faction(a).Money > 150 ` If it has less than 200 Knights, max cap, and more than 150 coins.
Inc Faction(a).MaxKnights
Dec Faction(a).Peasants ` Costs 1 Peasant per knight
Dec Faction(a).Money, 100 ` Costs 100 Coins per knight
Faction(a).Latest = "Trained a peasant to become a Knight."
EndIf
EndIf
EndIf
Faction(a).DecisionCounter = Faction(a).STime ` Something that works is needed here this does not work
Endif
Next a
Stuff like this simply wont work with the above. It still goes haywire and still makes them all pick the same decision number or no numbers at all, when i want them picking different numbers at different times.
I know exactly why the above does not work, this is only what i last tried. Trying to work out why the above does not work is pointless because it is obvious. I can see exactly where it has gone wrong, after a quick run through of it. Its merely the last thing i wrote. I am going wrong along the same lines as these. I am hoping the code points someone in the direction i was going, as i am not trying to fix the above code with an explenation, i know why its naff.
This is such a silly and simple problem about maniuptaing very simple numbers and variables but it certainly has me stumped.