Jump to content




parallel help


  • You cannot reply to this topic
11 replies to this topic

#1 etopsirhc

  • Members
  • 122 posts

Posted 05 March 2013 - 01:30 PM

can parallel.waitForAny call functions that sleeps for 5 min while the other waits for an event to trigger ?

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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 etopsirhc

  • Members
  • 122 posts

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

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 05 March 2013 - 01:53 PM

what is meant to be causing the player event? is it a peripheral?

#5 etopsirhc

  • Members
  • 122 posts

Posted 05 March 2013 - 01:57 PM

its the player detector from misc peripherals

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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?

#7 etopsirhc

  • Members
  • 122 posts

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

#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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
Spoiler


#9 etopsirhc

  • Members
  • 122 posts

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?

#10 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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 :P

#11 etopsirhc

  • Members
  • 122 posts

Posted 05 March 2013 - 02:21 PM

lol ok ^^ ty

#12 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 05 March 2013 - 02:35 PM

no problems.

something additional you could also do is change this
if event[1] == 'timer' and event[2] == timeout then
to this
if event[1] == 'timer' and event[2] == timeout and output then
that way your Log doesn't get spammed with timeout disabling.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users