TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Project26 from 100 Days of Swift (UIKit) error - Cannot find 'addChild' in scope

Forums > 100 Days of Swift

I'm working on project 26 and got it all working but then I decided to move all the code that dealt with creating a level into its own struct.

Now, I get a compiler error on all the 'load' methods when calling addChild(node). I've searched around but wasn't able to find anything that explained this or how to fix it. I even tried chatGPT but it was no help.

What am I doing wrong?

Here is a gist of the struct

3      

@twostraws  Site AdminHWS+

The calls to addChild() should be inside your game scene, because that's where the method exists. Structs generally work best when they store simple, inert data, rather than trying to take action in your game.

3      

Thanks. I ended up removing the addChild() calls in the struct and then just created the nodes in my game scene by looping through an array created in the struct.

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.