0 Favourites

To make each inst. do stuff at different intervals

  • Hi everyone,

    First of all, here is a stripped down .capx with the single relevant event.

    <img src="http://dl.dropbox.com/u/3138530/a.png" border="0">

    I have a sprite named "Enemy" that has an instance variable named "AttackInterval" Every time the amount of time set in AttackInterval is passed, the value is recalculated with choose or random and a bullet is launched from the sprite.

    I would like this recalculation to occur for every instance of the "Enemy" sprite seperately so that the bullets are launched in seperately calculated intervals.

    When I say:

    Every Enemy.AttackInterval seconds -> Enemy Set AttackInterval to choose (2,4)

    It does indeed recalculate the variable values in each instance seperately.

    But then it only takes the number of the first picked instance into account and the other instances obey to the picked instance, all firing the bullets together.

    I'm almost certain this behaviour is intended for other practical uses but the proper C2 syntax to get this thing occur the way I want it is unclear to me. "Every Self.AttackInterval seconds" can not work as "Self" can not be assigned to system objects and my attempts with "pick all" and "for each" combinations have all failed.

    The .capx I linked above demonstrates how each instance can be resized according to their own variable but the rest is lost to me. It's probably a simple matter but assure you, I have spent several days solving other seemingly complex problems with my project and am now legitimately stuck. :p

    Thanks all for reading.

  • Adding dt to a variable counts up 1 every second.

    So try adding another "AttackTimer" instance variable and doing:

    + Every tick

    -> Enemy: Add dt to AttackTimer

    + Enemy AttackTimer >= AttackInterval

    + For each Enemy

    -> Run timer event with Enemy

    System conditions like "Every X seconds" only run once without any regard for object picking, so usually instance variables is the best way around that.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Thanks but I'm having a hard time putting it to action. :/

    Your pseudocode works for telling the instances when to start do things but I can't get attackintervals to work afterwards. Once "Enemy AttackTimer >= AttackInterval" becomes true bullets are fired from all picked instances every tick or I need to pick only one again. (enable the disabled condition in this relevant .capx)

    Also I really don't want to make picking to effect the timing itself because my control over timing is crucial for this project.

  • Ashley

    Ok I were too early to give up and can't thank you enough.

    This works.

    I had problems with dt thought. Bullet synchronization was very off that way so I'm adding exactly 1 to AttackTimer every second. I hope I won't be sorry later. :)

  • Oops, I forgot to add: you reset the timer with "Subtract Enemy.AttackInterval from AttackTimer". If you just set it to 0, you introduce small errors, e.g. if it was 0.1 over the interval, that gets ignored.

    Here's a perfectly synchronised version using dt: http://dl.dropbox.com/u/15217362/attackinterval.capx (using dt is better than using 'every' because it should be more accurate)

  • Working nicely Ashley, thanks again. :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
167 14,489
DMT2005's avatar
DMT2005
Unread sticky
1 Favourites
C2 Games made with CocoonIO
136 89,814
minhcuong's avatar
minhcuong
Unread hot topic
99 10,136
karshinkoff's avatar
karshinkoff