Page 1 of 1

Answer to yesnoPopup

Posted: Wed Dec 29, 2021 1:23 pm
by helminthauge
I wonder how many of you have found the yesnoPopup stupid. Why tf the codes under this popup will be excuted right after the popup instead of after the selection is made? I know that it's assumed that the codes related to the selection should be put into the fct parameter, but in some cases we really want to return something according to the selection.
To make things worse, Lua doesn't support multithreading.

After some complaining and days of researching, I come out with a solution:

Code: Select all

local ret = nil
local main = coroutine.running()
Dialog:yesnoPopup("title", "context", function(ok)
	ret = ok
	coroutine.resume(main)
end)
coroutine.yield()
return ret
I put this into a use_power.use and it works well. However if you just execute coroutine.yield() out of the game and without anything else you'll get an error "attempt to yield from outside a coroutine". So there could be situations where this solution doens't work.

Re: Answer to yesnoPopup

Posted: Wed Dec 29, 2021 3:41 pm
by Zizzo
I think that's what engine.ActorTalents:talentDialog() and related methods are supposed to be used for. engine.ActorTalents:useTalent() sets up the necessary coroutine context for the resume/yield stuff to work, as does mod.class.Player:playerUseItem(), which is why your use-item code works in that context (as it's doing more or less the same thing as :talentDialog()). I agree, though, it's less than ideal.