Rare "Wait + Every _ Seconds" Causes Freezing

0 favourites
  • 5 posts
From the Asset Store
Like tourists, Travel around the world as fast as you can!
  • Hey there! I've been trying to essentially give this "Boss" a wind-up attack in which it chooses to perform this attack every 20 seconds, and while performing this wind-up it would first toggle on a "charging" boolean(which is a condition of the normal attack, it being FALSE that is), and then it will wait 5 seconds before finally choosing a party member to attack, then toggling the "charging" boolean off again.

    The problem I've been running into, is that every blue moon of running the game, the boss will completely stop performing ANY actions after starting it's wind-up move. It won't land the attack, nor will it continue to do anything else.

    drive.google.com/file/d/16mtp_6O8Lf_k3LUV2xpMLrIsORBkogeK/view

    ^Here is a link to my c3p, please with all my heart, this is a personal project do not steal <3

    gyazo.com/b946795719d2c624e85e173328acd732

    ^Here is a screenshot link to the exact codechunk that is the heart of the wind-up attack.

    I would be so so forever grateful if anyone is able to help me understand and fix this issue! Thanks so so much!

    Tagged:

  • Never use "Wait" and "Every X seconds" with long duration when programming game mechanics. You have no control over these events. "Every 20 seconds" may fire when you just started the level, as it's based on the project time, not on layout time. "Wait 5 seconds" is also bad, because in these 5 seconds something may change (the boss may already be dead for example), and you can't cancel the scheduled actions.

    Use Timer behavior instead. You can pause or cancel the timer, check the remaining time, run different timers for different object instances etc.

    .

    Another issue with your code is that most of your events are running on every tick. This is bad for performance and makes the code difficult to manage. But most importantly many of these events are not supposed to be run on every tick, for example events 9-12 will create lots of duplicate text objects.

    Instead of a "state machine" with dozens of global variables, use triggered events and functions.

  • Thank you very much for your thoughtful feedback! I’ll do some research into timers to replace the waiting and seconds!

    In terms of replacing the “every tick”, would I simply just make the requirements triggered by a value being set/changed? I’m super new to all this, so this was the most “english” way to make the game so far to me haha

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Most of your code is what's called "state machine". You have a bunch of variables and checking their states on every tick.

    I prefer keeping everything in triggers and functions, this code is shorter, cleared and much better for performance.

    Here is an example of state machine code:

    On collision with Enemy : Subtract 10 to health
    
    On collision with HealthPotion : Add 10 to health
    
    If health>100 : set health to 100
    
    If health<=0 : Set isDead=true
    
    If isDead=true : Player start animation "dead"
    
    and so on....
    

    There are too many events, most of them running on every tick.

    Here is how I would do it:

    You can call the function from other events, where the player gets hurt.

  • Thank you very very much, I’m grateful there are people like you on the forums willing to help us noobies free of charge.

    I see exactly what you mean now, and will try to get as far away as I can from statemachine code! Thank you very much for the example code of both styles. I will also appreciate the performance boost as that will be helpful overall I’m sure. Appreciate the help again!

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