This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
PixelFox's profile picture

parallel.waitForAll doesn't seem to work for me.

Started by PixelFox, 25 July 2015 - 02:55 AM
PixelFox #1
Posted 25 July 2015 - 04:55 AM
I'm working on a platformer. And I tried using parallel.waitForAll for the collision (Otherloop()) + moving (Mainloop())
And it doesn't seem to work, it's about bed time for me, so I won't be able to respond to you all, but here's the code:
http://pastebin.com/ueZqGpBG
Please help! (It's 12:00 over here)
Edited on 25 July 2015 - 03:02 AM
Balthamel #2
Posted 25 July 2015 - 05:51 AM
You're calling the function by using Gameloop() you need to pass the function iteslf by just using the name Gameloop
HPWebcamAble #3
Posted 25 July 2015 - 07:17 AM
You're calling the function by using Gameloop() you need to pass the function iteslf by just using the name Gameloop

To expand on that a bit:


local function testFunc()
  print("test")
end

type( testFunc ) --#> function

type( testFunc() ) --#> nil (It doesn't return anything, if it returned something, obviously this would give you that type)

The parallel API needs the FUNCTION value, so it can run the function itself.
Edited on 25 July 2015 - 05:18 AM
Bomb Bloke #4
Posted 25 July 2015 - 08:23 AM
You've also got your Gameloop / Otherloop functions calling themselves recursively. Use "while" loops instead.

http://lua-users.org/wiki/ControlStructureTutorial
PixelFox #5
Posted 25 July 2015 - 01:40 PM
You've also got your Gameloop / Otherloop functions calling themselves recursively. Use "while" loops instead.

http://lua-users.org...ructureTutorial

I know what while loops are, I just challenged myself by making a video game without using any loops.
Platformer it is!

Also, thanks to everyone who told me how I messed up :P/>
Edited on 25 July 2015 - 11:44 AM
SquidDev #6
Posted 25 July 2015 - 01:57 PM
I know what while loops are, I just challenged myself by making a video game without using any loops.
Platformer it is!

You'll probably want to use tail calls:


-- Produces a stack overflow - too many nested functions
local function foo()
  -- do something ...
  foo()
end

-- Works fine
local function foo()
  --do something
  return foo()
end