Answer to yesnoPopup

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
helminthauge
Wyrmic
Posts: 212
Joined: Sat Sep 29, 2018 3:43 am

Answer to yesnoPopup

#1 Post 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.

Zizzo
Sher'Tul Godslayer
Posts: 2520
Joined: Thu Jan 23, 2003 8:13 pm
Location: A shallow water area south of Bree
Contact:

Re: Answer to yesnoPopup

#2 Post 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.
"Blessed are the yeeks, for they shall inherit Arda..."

Post Reply