turingmachine
Emperor
- Joined
- May 4, 2008
- Messages
- 1,438
Okay I think I've really confused myself with this.
I have an array of buildings.
I have a for loop.
I check the city for buildings in the array.
I need the event to fire only if none of the buildings in the array are present in the city.
Doing something like:
Doesn't work. That would still fire even if one of the buildings was present in the city as the check would pass for all the other buildings. However I need it to only work if none of the buildings are present.
I tried to do a count, but I don't think I know how to do it properly.
I thought that would check if the city had any of the buildings in the array, if there were any it would raise the count. Then it would only fire if none of the buildings were present in the city (i.e. the count was 0). However this didn't work and it still goes through if only one of the buildings in the array is present.
Can anyone give me some advice? Thanks.
I have an array of buildings.
I have a for loop.
I check the city for buildings in the array.
I need the event to fire only if none of the buildings in the array are present in the city.
Doing something like:
Code:
for _, iBuilding in pairs(buildings) do
if not pCity:IsHasBuilding(iBuilding) then
Doesn't work. That would still fire even if one of the buildings was present in the city as the check would pass for all the other buildings. However I need it to only work if none of the buildings are present.
I tried to do a count, but I don't think I know how to do it properly.
Code:
for _, iBuilding in pairs(buildings) do
local count = 0
if pCity:IsHasBuilding(iBuilding) then
count = count + 1
end
if count == 0 then
I thought that would check if the city had any of the buildings in the array, if there were any it would raise the count. Then it would only fire if none of the buildings were present in the city (i.e. the count was 0). However this didn't work and it still goes through if only one of the buildings in the array is present.
Can anyone give me some advice? Thanks.