can parallel.waitForAny call functions that sleeps for 5 min while the other waits for an event to trigger ?
parallel help
Started by etopsirhc, Mar 05 2013 01:30 PM
11 replies to this topic
#1
Posted 05 March 2013 - 01:30 PM
#2
Posted 05 March 2013 - 01:39 PM
yes it can
local function listener()
local event = { os.pullEvent() }
-- do something
end
local function sleeper()
while true do
sleep(300)
-- do something
end
end
parallel.waitForAny(sleeper, listener)
#3
Posted 05 March 2013 - 01:45 PM
its kinda messy but heres what mine looks like ( and it isnt working )
http://pastebin.com/L6uf6PiD
i can get the program to run , but when after parallel startes it doesnt seem to get the event
http://pastebin.com/L6uf6PiD
i can get the program to run , but when after parallel startes it doesnt seem to get the event
#4
Posted 05 March 2013 - 01:53 PM
what is meant to be causing the player event? is it a peripheral?
#5
Posted 05 March 2013 - 01:57 PM
its the player detector from misc peripherals
#6
Posted 05 March 2013 - 02:00 PM
ahh ok.
so if I'm understanding correctly, this program is meant to turn the mob farm on when a player arrives, and then turn off after 5 minutes? or when the player leaves?
so if I'm understanding correctly, this program is meant to turn the mob farm on when a player arrives, and then turn off after 5 minutes? or when the player leaves?
#7
Posted 05 March 2013 - 02:02 PM
pretty much yes , player activates the detector , it turns on the farm for 5 min , but the player can then turn it off by hitting the detector again.
the hitting it again part ( and posibly the time out , havent tested that part yet ) doesnt work
the hitting it again part ( and posibly the time out , havent tested that part yet ) doesnt work
#8
Posted 05 March 2013 - 02:11 PM
Ok so for something this simple you don't really need to use the parallel api, you can instead just use a pull event loop with timers, where you can check if the event is 'player' or if it is 'timer'
something like this
something like this
Spoiler
#9
Posted 05 March 2013 - 02:17 PM
so the timeout = os.startTimer(3) is where i'd put the 5 min delay (300) and then the rest looks like it'd work perfictly
[edit] though not sure if i get the ( output and "activated" or "deactivated" ) part, is that just a simple inline if to return one of the strings?
[edit] though not sure if i get the ( output and "activated" or "deactivated" ) part, is that just a simple inline if to return one of the strings?
#10
Posted 05 March 2013 - 02:20 PM
yes exactly. sorry i was using 3 seconds to test the code, forgot to change it for you
#11
Posted 05 March 2013 - 02:21 PM
lol ok ^^ ty
#12
Posted 05 March 2013 - 02:35 PM
no problems.
something additional you could also do is change this
something additional you could also do is change this
if event[1] == 'timer' and event[2] == timeout thento this
if event[1] == 'timer' and event[2] == timeout and output thenthat way your Log doesn't get spammed with timeout disabling.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











