Skip to content

A few more questions #126

Answered by gilzoide
TennoAntenno asked this question in Q&A
Jul 9, 2025 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

Hey @TennoAntenno , welcome back!

  1. Is it possible to pause a coroutine? I'd like to be able to pause (or end) the currently running code, for example by pressing a button.
  2. How can I prevent infinite loops? Running something like while true do end freezes the entire game. Is there a way to guard against this?

You can use a count hook to yield coroutines whenever they execute count instructions (added in Lua GDExtension 0.4.0). This fixes the infinite loops, as well as make it possible for you to just discard the coroutine without ever resuming it, for example with the press of a button.

You can setup count hooks in GDScript like so:

const COUNT = 1000

func _coroutine_hook_func(debug_info

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@TennoAntenno
Comment options

@gilzoide
Comment options

@TennoAntenno
Comment options

@TennoAntenno
Comment options

@gilzoide
Comment options

Answer selected by TennoAntenno
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants