ToME: the Tales of Maj'Eyal

Everything about ToME
It is currently Tue Nov 21, 2017 4:23 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Nested :talentDialog()s?
PostPosted: Sun Aug 27, 2017 3:42 am 
Offline
Sher'Tul

Joined: Thu Jan 23, 2003 8:13 pm
Posts: 1404
Location: A shallow water area south of Bree
So, say you have a blocking dialog launched via ActorTalents:talentDialog(). From this dialog, you need to bring up another subdialog and block waiting for a response from it. (In my case, these are, respectively, the Alchemy artifact creation dialog and a subdialog to choose which ingredients to use for various artifact flags.)

Just calling :talentDialog() again obviously doesn't work (well, it's obvious now that I've tried it and it broke badly… :oops: ). The second most obvious approach is to mimic the coroutine juggling done by :talentDialog() itself:
Code:
function _M:nestedTalentDialog(d)
  local co = coroutine.create(function()
    print('[DEBUG] entering nestedTalentDialog coroutine')
    local ret = self.actor:talentDialog(d)
    print(('[DEBUG] nestedTalentDialog coroutine returning %s'):format(tostring(ret)))
    return ret
  end)
  local ok, ret = coroutine.resume(co)
  print(('[DEBUG] nestedTalentDialog returned %s, %s'):format(tostring(ok), tostring(err)))
  if not ok then
    print(debug.traceback(co))
    if ret then error(ret) end
    return nil
  end
  return ret
end

This, unfortunately, doesn't work; the coroutine.resume() returns immediately, which isn't the intended effect. So apparently either I've got the coroutine juggling wrong (I hope) or what I'm trying to do isn't possible (which would be bad).

I'm hoping someone more familiar with Lua coroutines than I am can see what I'm doing wrong here. Any ideas? I'm really not sure how I can rearchitect this if this can't be done…

_________________
"Blessed are the yeeks, for they shall inherit Arda..."


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group