Construct crashes when I run this code

  • I am trying to create a system where an enemy shoots once per second if it has line of sight to the player by using a While loop. However when I try to run the preview it opens to a black screen, and when I close it Construct has frozen.

    Here is the offending piece of code

    If anyone can help me figure out either why this is crashing or a different method I would very much appreciate it.

  • A loop means to run everything in the code until it is complete. The cycle, or tick cannot finish until the loop is done.

    Using While as is makes it so that it may never complete, so the system crashes.

    Don't use While unless you know for sure what you are doing.

    If you want it to run every second then use the Every x milliseconds condition under system as a sub event of the Los condition.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Use 'Has LineOfSight to Player' as the only condition and it automatically runs every tick. But i dont think that you want to spawn two bullets every tick.

    Use the Turret behavior and its setting for the fire rate. If you do not use this behavior, create a sub-event and select 'Every X Seconds' as a condition.

  • Thank you for the responses, and I've changed it to use the every second thing under the LOS event.

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