Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to have latent calls? #18

Closed
iUltimateLP opened this issue Oct 17, 2020 · 2 comments
Closed

Able to have latent calls? #18

iUltimateLP opened this issue Oct 17, 2020 · 2 comments

Comments

@iUltimateLP
Copy link

Hey, I want to use this to implement robots in my puzzle game.

An example Lua code would look like this:

robot.walkForward()
robot.turnLeft()
robot.walkForward()

As you can see, I'd need the calls to be "blocking", or non-returning until the robot fully finished moving. Is that possible? Thanks!

@rdeioris
Copy link
Owner

rdeioris commented Oct 17, 2020

@iUltimateLP you can use coroutines. Start by wrapping (you have various ways) the sequence of moves in a coroutine:

local robot = {}

function robot.actions()
  -- get the currently running coroutine
  coro = coroutine.running()
  print('actions!')
  -- pass the 'coro' to the blueprint to allow resuming later
  robot_up(coro)
  print('first step done')
  -- this yield will suspend the coroutine, it will be resumed by the previous blueprint
  coroutine.yield()

  -- and again...
  robot_up(coro)
  print('second step done')
  coroutine.yield()

  -- and again...
  robot_up(coro)
  print('end of coroutine')
end

return robot

the robot_up function is a blueprint event (note how it calls the resume over the passed coroutine):

immagine

you can directly spawn coroutine from blueprint/c++ (otherwise just use lua):

immagine

@iUltimateLP
Copy link
Author

Great, thanks for your detailed answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants