Jump to content




parallel API question


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

#1 Alexander0507

  • Members
  • 42 posts

Posted 24 August 2014 - 12:39 AM

Basicly I want function 1 waiting for a chat message (openperiphal) while function 2 does some other stuff (other OP stuff)
so with the parallel api,
So do I just do this or what ? :
function func1()
os,pullEvent("chat_message")
end

function func2()
--do stuff
end

while true do
prarallel.waitForAny(func1,func2)
end


#2 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 24 August 2014 - 12:55 AM

Not exactly, as two things are wrong with that function, one, prarellel is not how you spell it :P and two, your os.pullEvent has a comma instead of a period, oh and you should probably make it a while true do loop for the os.pullEvent. Anyways other than that, it should do it, however should one end, then it will restart both. If you're wanting it to wait until both end, then using waitForAll will only stop when ALL have finished :P

Edited by Dragon53535, 24 August 2014 - 01:01 AM.


#3 natedogith1

  • Members
  • 110 posts

Posted 24 August 2014 - 12:56 AM

essentially, though you might not want to surround the parallel call with a while true do, parallel.waitForAny will run the functions until one of them exits on its own.

#4 Alexander0507

  • Members
  • 42 posts

Posted 24 August 2014 - 01:19 PM

Ok I removed the while true do from the pullEvent but when I try to run the code my whole client crashes xD

Crash log: http://pastebin.com/0tBGJdMX

Code: http://pastebin.com/xaba31Wm

#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 24 August 2014 - 01:21 PM

I would suspect this has something to do with the fact that you are toggling redstone on/off more than 10 times/second. You may want to put a sleep in there.

#6 Alexander0507

  • Members
  • 42 posts

Posted 24 August 2014 - 01:31 PM

Okay yeah that worked :D

now my problem is that it only checks for the event once and then only does the redstone stuff :(
Basicly I want it to check for the event all the time while doing the redstone stuff

#7 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 24 August 2014 - 01:53 PM

function f1()
  while true do
    local e, msg = os.pullEvent( "chat_message" )
    print( e .. " - " .. msg )
  end
end

function f2()
  while true do
   rs.setOutput( "right", not rs.getOutput( "right" ) )
   sleep( 1 )
  end
end

parallel.waitForAny( f1, f2 )

Edited by KingofGamesYami, 24 August 2014 - 01:53 PM.


#8 Alexander0507

  • Members
  • 42 posts

Posted 24 August 2014 - 01:56 PM

That is what I had

but it didn't get any event even with out the chat message filter

#9 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 24 August 2014 - 02:26 PM

Were you sending it any events? It should work as you said, redstone turning on/off while receiving chat messages.

#10 Alexander0507

  • Members
  • 42 posts

Posted 24 August 2014 - 02:35 PM

With openperiphal you can send these chat messages over the terminal glasses when you type something with $$ in the chat.
But when I did it nothing changed . The computer didn't print anything and the redstone still changed

#11 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 24 August 2014 - 02:46 PM

Strange, try without parallel:
local id = os.startTimer( 1 )
while true do
  local event = { os.pullEvent() }
  if event[ 1 ] == "chat_message" then
    print( event[ 1 ] .. " - " .. event [ 2 ] )
  elseif event[ 1 ] == "timer" and event[ 2 ] == id then
    rs.setOutput( "right", not rs.getOutput( "right" ) )
    id = os.startTimer( 1 )
  end
end


#12 Alexander0507

  • Members
  • 42 posts

Posted 24 August 2014 - 02:49 PM

still doesn't print anything :(

#13 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 24 August 2014 - 02:51 PM

Are you sure "chat_message" is the event and not "message_chat" or something else?

#14 Alexander0507

  • Members
  • 42 posts

Posted 24 August 2014 - 02:52 PM

just tested without the multitasking and it seems like something with the chat message at all isn't working

It was chat_message I will ask on irc chat

#15 Alexander0507

  • Members
  • 42 posts

Posted 24 August 2014 - 03:03 PM

ok It is chat_command now :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users