Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Coroutines in gideros 2016.06 — Gideros Forum

Coroutines in gideros 2016.06

test29test29 Member
edited July 2016 in General questions
If I have coroutine in one scene and after that scene is restarted, new coroutine call is added on each restart of scene to the existing one (something like timers), so after second restart I have two coroutines running, after third restart, three coroutines running, etc... Is this a case or something else is wrong in my code?

Is there I way to stop coroutine from executing?

Comments

  • SinisterSoftSinisterSoft Maintainer
    A coroutine will stop executing when it runs out of code to run.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • test29test29 Member
    I have loop in my coroutine, that doesn't stop when the scene is ended (scene is ended by event rising). When that scene is restarted, logic of scene is behaving like there are more than one loop (more than one coroutine) is running. When scene is starting for the first time everything is working OK, problem is only when it is restarted.
  • SinisterSoftSinisterSoft Maintainer
    Have a global flag in the loop, change the flag to exit the loop.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • test29test29 Member
    I know that I can make it work that way, but in my case it wont work, because in my coroutine I have many calls to different functions (and every function that is called from coroutine, behave itself like coroutine), and it seems that somehow coroutine remains active. So after every scene restart new coroutine is added while older are still active.

    Is there a way to forcefully stop coroutine, something like 'StopCoroutine' in c#?
  • SinisterSoftSinisterSoft Maintainer
    So if you call a function in a co-routine, it starts a new co-routine for you? That doesn't sound right.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • test29test29 Member
    No, if you call function in a coroutine, called function behaves like coroutine, you can use core.yield in it.
  • hgy29hgy29 Maintainer
    @test29,

    I understand what you need, when I coded corotuine based threads I didn't see the need of having a function to kill them because in most languages this is a bad thing to do.
    However in lua and its GC, this is something possible and not that bad after all. So probably we'll add it soon.
  • test29test29 Member
    Thank you, that would be great. Also it would be usefull if it could be tested that coroutine is active or not.
  • SinisterSoftSinisterSoft Maintainer
    @test29 A function called by a coroutine doesn't start a new coroutine. It's still part of the original coroutine. When it returns then the coroutine will carry on until the end and then exit.

    eg:
    function test2()
    	while true do
    		print("only this will print")
    	end
    end
     
    function test1()
    	test2()
    	while true do
    		print("does this ever print?")
    	end
    end
     
    Core.asyncCall(test1)

    Likes: MoKaLux

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.