Conversion error from 'Void' to 'SKAction'

Hello,
I am programming an app and I’ve got a problem with a function that is supposed to push a Node from the edge of the right screen to the middle. The code is like this:

//line 89
//line 90
let MoveBlueToMid = blue.run(SKAction.move(to: CGPoint(x: frame.midX, y: frame.midY), duration: 10))
func moveBlue() → SKAction {
let moveToMidBlue = blue.run(SKAction.moveTo(x: frame.midX, duration: 10))
return SKAction
}
/func moveRed() {
red.run(SKAction.move(to: CGPoint(x: frame.midX, y: frame.midY), duration: 10))
}
func moveGreen() {
green.run(SKAction.moveTo(x: frame.midX, duration: 10))
}
func moveYellow() {
yellow.run(SKAction.move(to: CGPoint(x: frame.midX, y: frame.midY), duration: 10))
}
/
func statusPlay() {
let moveMidBlue = blue.run(MoveBlueToMid)
let repeating = SKAction.repeatForever(action: SKAction)
}
} // End of didMove(to: SKView)

Now the first problem is in line 97. The error message says: Cannot convert return expression of type ‘SKAction.Type’ to return type ‘SKAction’

The second problem is in line 114 with the error message: Cannot convert value of type ‘Void’ to expected argument type ‘SKAction’

Can you tell me how I can solve these problems or how would you code it?
Thank you already and have a great day.

The first error is for this line:

return SKAction

That is returning a type. The func declaration says it should return an instance of SKAction. Maybe you meant to return MoveBlueToMid?

The second error is for this line:

let repeating = SKAction.repeatForever(action: SKAction)

You are trying to pass the type SKAction as the action parameter. Again it is expecting an instance of SKAction. Maybe you meant moveMidBlue?

I can’t work out what you are trying to do, so I’m not sure how to correct it, but those are the spots that are causing the error messages.

Hi,
at first thank you for the answer. I want to push a Node that I called “blue” to the mid (x: frame.midX, frame.midY) from a starting position that is on the right site of the screen (x: frame.maxX, y: frame.midY) Now I’ve typed in what you told me: “That is returning a type. The func declaration says it should return an instance of SKAction. Maybe you meant to return MoveBlueToMid?” And this error message was gone. Thank you for that!! Now there is a second error in the line that says:

let repeating = SKAction.repeatForever(moveBlue())

The error message in this line says:

“Editor placeholder in source file”

Below (moveBlue()) is a read line, so moveBlue() is the problem.

I want that the Node “blue” is getting pushed in the middle of the screen (x: frame.midX, y: frame.midY) by the function moveBlue and that this is repeating all the time. I know that I have to make a function that pushes the node back to the start point wich is x: frame.maxX, y: frame.midY. How would you code it and what can I do against this error message? I’m pretty sure that it is such a simple error :confused: .
Thank you already for your answer it already helped me.
Have a great day! :slight_smile:

This topic was automatically closed after 166 days. New replies are no longer allowed.