Jump to content




Parallel API


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

#1 Zenon

  • Members
  • 50 posts

Posted 21 July 2015 - 01:00 AM

Hi all! I was just reading up on parallel api, and was making a little test code . . .

This will wait for input, though it wont respond to getting it:
Spoiler

This wont draw errors, but wont wait for input:
Spoiler

Any ideas? Thanks in advance!

#2 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 21 July 2015 - 01:27 AM

You need to place content of the functions into an infinite loop. Also, you should not add parentheses. If you really have to call the function with arguments, you have to use an anonymous function.

 
local f1 = function() 
  while true do
    --do the event stuff here 
  end
end

local f2 = function(...) 
  --the same as above
end

parallel.waitForAll(f1, function() 
    f2("Random","arguments","foo","bar")
  end) 

Edited by H4X0RZ, 21 July 2015 - 02:33 AM.


#3 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 21 July 2015 - 01:40 AM

In most situations, you don't need to use the parallel API, though it is good to know how to use it and how it works.


View PostH4X0RZ, on 21 July 2015 - 01:27 AM, said:

parallel.waitForAll(f1, function()
	f2("Random","arguments","foo","bar")
  end

You missed a closing parenthese at the end

#4 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 21 July 2015 - 02:34 AM

View PostHPWebcamAble, on 21 July 2015 - 01:40 AM, said:

In most situations, you don't need to use the parallel API, though it is good to know how to use it and how it works.


View PostH4X0RZ, on 21 July 2015 - 01:27 AM, said:

parallel.waitForAll(f1, function()
	f2("Random","arguments","foo","bar")
  end

You missed a closing parenthese at the end

Oh, thanks for telling me! I'm on my phone right now, pretty hard to write code on it xD

#5 Zenon

  • Members
  • 50 posts

Posted 21 July 2015 - 02:47 AM

View PostH4X0RZ, on 21 July 2015 - 01:27 AM, said:

You need to place content of the functions into an infinite loop. Also, you should not add parentheses. If you really have to call the function with arguments, you have to use an anonymous function.

local f1 = function()
  while true do
	--do the event stuff here
  end
end

local f2 = function(...)
  --the same as above
end

parallel.waitForAll(f1, function()
	f2("Random","arguments","foo","bar")
  end)

Thanks a bunch!

#6 flaghacker

  • Members
  • 655 posts

Posted 21 July 2015 - 06:15 AM

parallel.waitForAll(e(), r())
Remove the parentheses after 'e' and 'r'. Here you're calling them, but you want to pass them to the function instead. Fixed code:
parallel.waitForAll(e, r)


#7 Zenon

  • Members
  • 50 posts

Posted 21 July 2015 - 07:21 PM

View Postflaghacker, on 21 July 2015 - 06:15 AM, said:

parallel.waitForAll(e(), r())
Remove the parentheses after 'e' and 'r'. Here you're calling them, but you want to pass them to the function instead. Fixed code:
parallel.waitForAll(e, r)
Yeah, I saw that while looking around . . . thats why I made the second code





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users