Problem with .name notation

Hey guys so I’m having a problem with this .name notation. It’s supposed to be connected to the name I set for it at the top of the primary class Pets. Im trying to call it but its not being recognized.

What fixes does the error offer when you expand the little red line?

It’s just saying it needs a ; after the name or saying it needs { because it thinks its gonna be a function and a (). Its not a func and I’ll give u a comparison of what I’m working on in the morning

Hi @David_Clark

It looks like there is 6(!) errors for the same line…
Can it be a problem of typo in your Class “Tamagatchi()”?
Could you post the full code to help further?

PS: Not related to the problem but it should be Tamagotchi if you are referring to the digital pet as tamago means egg in japanese

This is the code to compare mine to.

var game = Tamagotchi()

game.name = “bunny”

for _ in 1…15 {

game.play()

game.feed()

game.clean()

game.sleep()

game.check()

}

game.getAge()

But above, how do you create the class Tamagotchi()?

Its a subclass of Pets Tamagotchi: Pets {

Without knowing how Pets() and Tamagotchi() classes have been defined, I think it will be difficult to help.

Thanks!

On line 162 from your first screenshot, you have the closing curly bracket of your class Tamagotchi:Pets which should have been closed on line 145.

1 Like

Also, the semicolon are not necessary at the end of each lines in Swift - but you might have added them when Xcode was throwing the error…

Ok thanks, nah I saw them and thought perhaps I’d need to add them because I knew that’s what I would eventually have to start doing anyway. (Optional) ur right tho.

Cool!
Don’t hesitate to mark as solution if it resolved your problem :wink:

So that solved my prob, but my real issue was figuring out why my getAge function isn’t being recognized!

Without parentheses after getAge the compiler thinks you are referencing a property of the object rather than a function.

1 Like

No I left it out on purpose. It still says it doesn’t identify getAge.

Please share (by copying and pasting) the whole code, I am sure someone will spot the problem for you quickly.

It would help a lot if you would post your entire code fenced in with ``` backticks instead of chopped up into screenshots that don’t show everything.

But for whatever reason—probably due to incorrectly balanced brackets, would be my guess—your Tamagatchi class does not actually contain a getAge() function like you think it does.

My suggestion: Put your cursor on line 141 and use Editor > Selection > Balance Delimiters repeatedly to make sure that everything is contained in the objects you think they are contained in.

1 Like

Also Command+A and Control+I would help with indentation

This is what my problem is. the func getAge is connected to the Tamagotchi subclass. Why when I call it out from the var name: var game = Tamagotchi(); Doesn’t it recognize itself?