0

I am trying to run an sksequence in which it waits for 60 seconds, then starts an endless loop but I keep getting the compiler error "Missing argument for parameter 'completion' in call" Here is my code:

runAction(SKAction.repeatAction((SKAction.sequence(([SKAction.waitForDuration(60),
        runAction(SKAction.repeatActionForever(
            SKAction.sequence([
                SKAction.runBlock(addBlock1),
                SKAction.runBlock(actualDuration1Reduc),
                SKAction.waitForDuration(blockWait1),])))]))), count: 1))

Can someone please help me? I am new to programming, so please just keep that in mind. Thanks

Arbitur
  • 38,684
  • 22
  • 91
  • 128
Leonard Parisi
  • 200
  • 1
  • 3
  • 12

1 Answers1

1

If you are new to programming, this is a bad time to try to learn Swift. As you have discovered, the Swift compiler often gives error messages that are completely useless. You would probably be better off learning Objective-C for now.

That aside, the root problem is that you're trying to use the return value from runAction, here:

runAction(SKAction.repeatAction((SKAction.sequence(([SKAction.waitForDuration(60),
    runAction(SKAction.repeatActionForever(
    ^^^^^^^^^
        SKAction.sequence([
            SKAction.runBlock(addBlock1),
            SKAction.runBlock(actualDuration1Reduc),
            SKAction.waitForDuration(blockWait1),])))]))), count: 1))

You're trying here to create an array with two elements: an SKAction (returned by waitForDuration(60)) and a Void (returned by runAction). The compiler needs to find a supertype of both of those: some common type of which both SKAction and Void are subtypes. You can see this explicitly by changing the statement to this:

let a = [SKAction.waitForDuration(60),
    runAction(SKAction.repeatActionForever(
        SKAction.sequence([
            SKAction.runBlock(addBlock1),
            SKAction.runBlock(actualDuration1Reduc),
            SKAction.waitForDuration(blockWait1)])))]

The compiler here generates a slightly more useful (but probably still incomprehensible to beginners) error message, “'SKAction' is not convertible to 'Void'”:

SKAction is not convertible to Void

So why are you getting that useless error message instead? Well, if you option-click on the a variable in my example, you'll discover that the compiler has assigned a special “error type” to a:

error type

Back in your original code, this error type percolates up the syntax tree, through the attempts to call SKAction.sequence and SKAction.repeatAction, causing each of those to return the error type. Finally the compiler gets back up to the top-level call to runAction. It tries to find a version of runAction that takes the error type as a parameter. No such version exists, so (apparently at random) it picks the runAction:completion: version. It then notices that you haven't passed the second (completion) argument to this call to runAction and gives you an error message informing you of your failure. And this is why compilers should not do drugs.

So what's the fix? Well, I'm not sure what you're trying to do in your code, because doing a repeatActionForever action inside a repeatAction action makes no sense. The outer (repeatAction) action will never get a chance to repeat because the inner (repeatActionForever) action will never stop repeating.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848