I edited the example to include some comments for clarification.yetneverdone wrote: ↑Mon Nov 04, 2019 11:19 pm The example seems complex, could be simplified i guess with more explanation?
it's cases like these why i created certain events like E.PollMouseActivity. An E.PollKeyboardActivity could probably be useful for something simple like that. I've done some testing with text boxes that have more functionality and my solution always tends to be more branching. Here's my example from GitHub modified, admittedly it gets quite a bit more complex, but can easily be scaled up to include more functionality like; cursor movement, delete key, copy, paste, all without increasing branching complexity much further.pgimeno wrote: ↑Tue Nov 05, 2019 11:30 pm I've just run into one. I'm writing a very straightforward input function that lets you enter characters and delete them. In your example, you create a branch in order to read TextInput, but to me it would be much clearer if I could poll both TextInput and KeyPress with a non-blocking function, in a loop where I would also call E.Step(). As things are, I have to repeat the display code both for the deletion and for the typing branches.
Code: Select all
local E = require "tlevent"
io.output():setvbuf("no")
E.O.Attach()
E.O.Do(function()
print("Hello!")
E.Wait(1)
print("What's your name?")
E.Wait(1)
local name = ""
local enter_name = E.Branch(function() -- wrapping branch
local old_name = ""
E.Branch("loop", function() -- display
print("Enter your name: " .. name)
old_name = name
repeat E.Step() until name ~= old_name
end)
E.Branch("loop", function() -- typing
local text = E.PollTextInput()
name = name .. text
end)
E.Branch("loop", function() -- deleting
E.PollKeyPress("backspace")
name = name:sub(1, -2)
end)
end)
E.PollKeyPress("return")
E.G.Kill(enter_name) -- will kill all the child branches too
print("")
E.Wait(1)
print("Hello " .. name .. ", nice to meet you!")
E.Wait(3)
print("[Press any key to exit]")
E.PollKeyPress()
love.event.push("quit")
end)
Here's the source for E.PollMouseActivity.
Code: Select all
function E.PollMouseActivity()
local pmm = E.Passive(E.PollMouseMove)
local pmp = E.Passive(E.PollMousePress)
local pmr = E.Passive(E.PollMouseRelease)
local pmw = E.Passive(E.PollMouseWheel)
while true do
E.Step()
E.PassiveStep(pmm, pmp, pmr, pmw)
if E.IsPassiveDone(pmm) then return "MouseMoved", E.GetPassiveResults(pmm) end
if E.IsPassiveDone(pmp) then return "MousePressed", E.GetPassiveResults(pmp) end
if E.IsPassiveDone(pmr) then return "MouseReleased", E.GetPassiveResults(pmr) end
if E.IsPassiveDone(pmw) then return "MouseWheel", E.GetPassiveResults(pmw) end
end
end
Code: Select all
function TL.Event.MouseActivity()
local pmm = TL(TL.Event.MouseMoved)
local pmp = TL(TL.Event.MousePressed)
local pmr = TL(TL.Event.MouseReleased)
local pmw = TL(TL.Event.WheelMoved)
while true do
TL.Event.Step()
pmm:Step(); if pmm:IsDone() then return "MouseMoved", pmm:GetResults() end
pmp:Step(); if pmp:IsDone() then return "MousePressed", pmp:GetResults() end
pmr:Step(); if pmr:IsDone() then return "MouseReleased", pmr:GetResults() end
pmw:Step(); if pmw:IsDone() then return "WheelMoved", pmw:GetResults() end
end
end