Multiple instances firing at different changing intervals

0 favourites
  • 9 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • In this capx you can create guns on point by left clicking and destroy them by right clicking.

    Every 0.1 seconds, the firing interval for the gun is set to random(0.1,1.0) The gun will then wait Gun.Interval seconds between each shot fired.

    The result is a gun that fires at constantly changing interval.

    However, when a second gun is introduced, both will be firing at the same changing interval. The desired result is to have them firing at a changing interval that is unique to each instance.

    Introducing the "For each Gun" condition causes only one gun to fire, no matter how many guns are present. (And I do not understand why that is.)

    --------------------------------------------------------------------------------------------------------------------------------------------------------------

    I am having this issue because I do not fully understand how picking works. I understand that there are many ways to work around this without getting into picking, but it is important I learn how to properly employ picking because in the game I am actually developing there are many more instance variables involved than just a changing interval and I can't get the system to understand which instances I am referring to even if they meet the variable conditions.

    For example, guns could have a variable for reloading (0: Reloading, 1: Loaded) and make a condition that the gun can not fire while reloading. Because I don't understand picking, what usually results is that when one gun is reloading, none will fire. Or whatever I am using to trigger the reload may cause only one of the guns to constantly be reloading for all the others while they continue to fire.

    .capx

    https://drive.google.com/file/d/13RpVWh ... sp=sharing

  • Use Timer behavior, it's perfect for this task:

    You can add a sub-event to "On timer" to check if the gun is reloading and only spawn bullet if not reloading.

  • Use Timer behavior, it's perfect for this task:

    You can add a sub-event to "On timer" to check if the gun is reloading and only spawn bullet if not reloading.

    Yes that is a perfectly fine work around, but I have plenty of those. What I am looking for is an example of how picking can be used to specify to the system which instance I am referring to.

    The reason for this is because in the game I am actually developing deals with many instance variables as conditions and because I do not have a working example of how to use picking in that situation I have to work around every little detail.

    Please read the whole post.

  • I realize now the title is probably misleading and I would change it but I'm not exactly sure how to concisely word what I am trying to learn about.

  • Your event "Every gun.interval seconds" only makes sense if there is 1 gun instance.

    When there are many guns, this event will not work as you expect. I believe it compares "interval" for the first instance only, but it doesn't do picking, that's why all your guns fire at the same time.

    Here is the way to do what you want without the timer:

    This event will pick one or several instances of the gun, only those that satisfy the condition (nextShot<time). Picked guns will fire and a new value will be set to their nextShot variable.

    Most events of the Gun object will pick Gun instances. For example "Gun->Compare instance variable", or "Gun->Is visible".

    Any sub-events or actions under this event will only apply to picked instances.

    Most events of the System object don't do picking (except for those that start with "For each" or "Pick").

    For example "System->Compare two values Gun.NextShot<time" will compare values, but it will not pick gun instances. So if you do Gun->Spawn bullet in this event, all guns will fire.

  • Your event "Every gun.interval seconds" only makes sense if there is 1 gun instance.

    When there are many guns, this event will not work as you expect. I think it compares "interval" for the first instance only, but it doesn't do picking, that's why all your guns fire at the same time.

    Here is the way to do what you want without the timer:

    This event will pick one or several instances of the gun, only those which satisfy the condition (nextShot<time). Picked guns will fire and a new value will be set to nextShot variable.

    Yeah that's pretty similar to a work around that I am already using. Let me try explaining the problem differently. Let's say the gun needs to cycle out a cartridge before it can fire again. (0: Chambered, 1: Cycling)

    The gun won't fire unless Cycling = 0

    But if Cycling = 1, it will wait Gun.Cycle_Time seconds and then set Cycling to 0 so that the gun can fire again.

    When there are multiple instances of the gun things start going wrong. With even just two guns they will eventually both lock up and I do not understand why. I am trying to understand why things like this are happening, not work around the problems. I can come up with solutions all day long, what I need is understand of why problems like these occur in the first place.

    New .capx with cycling mechanic

    https://drive.google.com/file/d/13RpVWh ... sp=sharing

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You mentioned earlier that the stating condition the "Every gun.interval seconds" only applies to the first instance, meaning that all other instances will fire on that interval instead of their one.

    Yes, that is the problem, I understand that. What I do not understand is why when I refer to an instance variable it doesn't take into account for each individual instance's unique variables. I am under the impression that there is a universal solution for getting the system to make instances behave independently based on their uniquely different variables.

  • What I do not understand is why when I refer to an instance variable it doesn't take into account for each individual instance's unique variables. I am under the impression that there is a universal solution for getting the system to make instances behave independently based on their uniquely different variables.

    When you refer to instance variable, the system actually does this "for each picked instance".

    Say, if you do "Gun set var to random(10)", a different random number will be set for each instance of the Gun.

    And if you do "Gun set scale to var", they will all become different sizes.

    As for the Timer - this is not a workaround. This is the right way to do things in C2 when you are dealing with multiple instances and delayed actions.

    If you only have 1 gun, you can use "Every x seconds" or "Wait", no problem.

    If you have multiple instances of gun and they are firing/reloading at different times, it may be really difficult to get them working correctly with all these "Every x seconds", "Trigger once" and "Wait" events.

    In your last capx the problem is with the "Trigger once" condition.

    After one gun has fired, event #5 is triggered, all good. Then a second gun fires, but the first gun still has Cycling=1, so this event will not be triggered, because it's still true and it has already triggered once.

    And then the first gun fires again, but event #5 is still true, so it's still not triggered and now both guns are stuck with Cycling=1.

    Here is a simple solution:

  • > What I do not understand is why when I refer to an instance variable it doesn't take into account for each individual instance's unique variables. I am under the impression that there is a universal solution for getting the system to make instances behave independently based on their uniquely different variables.

    >

    When you refer to instance variable, the system actually does this "for each picked instance".

    Say, if you do "Gun set var to random(10)", a different random number will be set for each instance of the Gun.

    And if you do "Gun set scale to var", they will all become different sizes.

    As for the Timer - this is not a workaround. This is the right way to do things in C2 when you are dealing with multiple instances and delayed actions.

    If you only have 1 gun, you can use "Every x seconds" or "Wait", no problem.

    If you have multiple instances of gun and they are firing/reloading at different times, it may be really difficult to get them working correctly with all these "Every x seconds", "Trigger once" and "Wait" events.

    In your last capx the problem is with the "Trigger once" condition.

    After one gun has fired, event #5 is triggered, all good. Then a second gun fires, but the first gun still has Cycling=1, this event will not be triggered, because it's still true and it has already triggered once.

    And then the first gun fires again, but event #5 is still true, so it's still not triggered and now both guns are stuck with Cycling=1.

    Here is a simple solution:

    Yes! Thank you so much dop2000, I'm starting to understand why I am running into these types of issues.

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