42 posts
Posted 24 August 2014 - 01: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
1080 posts
Location
In the Matrix
Posted 24 August 2014 - 01: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 on 24 August 2014 - 12:01 AM
108 posts
Posted 24 August 2014 - 01: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.
42 posts
Posted 24 August 2014 - 02: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/0tBGJdMXCode:
http://pastebin.com/xaba31Wm
3057 posts
Location
United States of America
Posted 24 August 2014 - 02: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.
42 posts
Posted 24 August 2014 - 02: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
3057 posts
Location
United States of America
Posted 24 August 2014 - 02: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 on 24 August 2014 - 12:53 PM
42 posts
Posted 24 August 2014 - 02:56 PM
That is what I had
but it didn't get any event even with out the chat message filter
3057 posts
Location
United States of America
Posted 24 August 2014 - 03:26 PM
Were you sending it any events? It should work as you said, redstone turning on/off while receiving chat messages.
42 posts
Posted 24 August 2014 - 03: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
3057 posts
Location
United States of America
Posted 24 August 2014 - 03: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
42 posts
Posted 24 August 2014 - 03:49 PM
still doesn't print anything :(/>
3057 posts
Location
United States of America
Posted 24 August 2014 - 03:51 PM
Are you sure "chat_message" is the event and not "message_chat" or something else?
42 posts
Posted 24 August 2014 - 03: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
42 posts
Posted 24 August 2014 - 04:03 PM
ok It is chat_command now :D/>