Collective Population repres. using instance var.

Get help using Construct 2

Post » Tue Feb 12, 2013 11:53 am

I am trying to create a strategy game with many regions for the player to take control over.

I represented each region with a sprite with Instance variables "population" and "owner". The "owner" variable basically keeps track whether the region is the players or not.

A small text box shows the total population of controlled regions. It works by checking whether the owner variable is one or not of different regions.

The problem I face is with higher number regions and with very poor technique I am using, the event sheet will fill up with various permutations of different regions.

If someone would kindly instruct me how to use some array or such to check whether instance variable "owner" is equal to 1 for all the sprites and add/display the population of the same sprites.


https://www.dropbox.com/s/ugb6dex6mr3dwha/regionswitchingplayers.capx

B
2
Posts: 2
Reputation: 254

Post » Tue Feb 12, 2013 12:00 pm

Variable TotalPopulation

Every 1 seconds
..Set TotalPopulation to 0
..For each Sprite
.. Sprite.owner = 1
... add Sprite.population to TotalPopulation
.. Set PopulationTextObject text to ("Population is " & TotalPoulation )


That will count every player owned sprites population together, was this what you were after?
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Tue Feb 12, 2013 5:17 pm

yess its working now.

Thank you so much.

But could you elaborate the logic of the population being reset to 0 every 1 second?
B
2
Posts: 2
Reputation: 254

Post » Tue Feb 12, 2013 5:19 pm

[QUOTE=yudodis] yess its working now.

Thank you so much.

But could you elaborate the logic of the population being reset to 0 every 1 second? [/QUOTE]

If you keep adding to it every second, you'll get your total population added to it once per second. That's why we need to set it 0 before 'refreshing' the value :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192


Return to How do I....?

Who is online

Users browsing this forum: emoticon, KeetonCat, makkancs, Matthew de and 25 guests