Collective Population repres. using instance var.

0 favourites
  • 4 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • 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.

    dropbox.com/s/ugb6dex6mr3dwha/regionswitchingplayers.capx

  • 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?

  • yess its working now.

    Thank you so much.

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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • yess its working now.

    Thank you so much.

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

    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 :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)