[SOLVED] Function Calling Problem

  • Here there

    I've been developing a game and came across a strange problem.

    I have various instances of object "computer". Now whenever they have line of sight to "player" they shoot towards the player. They all show after every X seconds . Now shooting actions are placed inside a function. so this is like whenever see the player, every X seconds call the shooting function to spawn a bullet. This all works fine.

    The problem arise when more than one instance has same number of seconds to call the shooting function. In this case when more than one instance has same number of seconds to call the function, then ONLY one of the instance call the shooting function. I don't know why.

    As in the above image, when each computer calls it different seconds, it works fine. But if for example two computers have the variable activeGun = 2, then this won't work. Only one of them calls the function

    Kindly help

  • You are trying to associate 'every X seconds' with an object, but it is a global event, so it will only run once per X seconds, no matter how many times you call it. You want to use the Timer behaviour, which is per object. Just change the timer period per gun value.

  • Maybe make it in a range of seconds. between 0.8 sec and 1.2 sec. Another thing to try is to add wait. Maybe again with a randomly selected value from floor(random( x, y )). I find that when something should be called and does not, IT may mean the code cannot be timely processed and IT does not take effect. Waiting or randomising or both have helped me.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Voytekblackhornet Thanks guys. Both of your solutions worked for me combined. That solved my problem.

    many thanks for helping me out

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