How do I set a condition based on a variable?

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi guys,

    hope someone can help me with this.

    So basically I have a guy working a farm, producing 1 food ever 2 seconds.

    the way this is set up is basically this: if the farm is empty -> call a function to make minions go to . on collision with it, the minion sprite is destroyed, and a value of 1 is added to farm's instance variable. when the value of 3 is reached, the function changes the behavior of the minions, so they would not be interested in it any longer.

    when the first minion enters the farm, 1 is added to farm's instance variable and also a boolean "isInhabited" set to true.

    the problem is that I have tried to make it so when there is only 1 guy working to add 1 to the global variable "food" ever 2 seconds, when 2 guys are working, i wanted to add 5 to food every 2 seconds or when farm's boolean "isFull" is set to true (meaning 3 farmers), to add 12 to food every 3 seconds.

    don't think i'm skilled enough to think this one through. here's an image with the best idea i've had so far..

    hopefully someone can illuminate me!

  • You need another variable to track workers on the farm. You can then use a condition event that checks the variable and if workers =1 then add 1 to food, if workers =2 then add 5, if workers = 3 then set boolean isFull and add 12 food.

    I would recommend not having the 12 be 3 seconds and 1 and 5 be 2 seconds... it just add a layer of difficulty that is not needed... just decide how much 3 workers will make in 2 seconds... this way you can put the above in one event that is triggered every 2 seconds.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I did just that and it worked! by checking a variable "farmerCount" i can then set how much food is produced every x seconds!

    As for the values, they're obviously not hammered in. this was just random numbers for testing purposes. Wanted to see a clear difference in value and time when testing at the end I would more than likely keep the food produced at an even number of every x seconds.

    Thanks for the tip

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