This is a very straightforward question and I’m sure it has something to do with the scope of my variable, but it’s telling me “earth” is not defined at the animate function, even though as far as I can tell it is (although obviously it’s not!)… Attaching Codepen, any help would be appreciated.
You declare the
earth variable within your
init() function. Hence, it is not visible for
Try to declare
earth at the same place where you declare
Thanks for the answer. Didn’t want to bog you down with details, which is why I crossposted. I’m still having trouble with the scope, even when I declare the earth variable outside of the init() function. I just can’t seem to get it to work. Any advice?
Please share your current progress as an editable fiddle/codepen. The community can then have a look at your code.
I attached this codepen into my initial post, here it is again:
Your codepen is still read-only and you still declare
I see that now, thanks for your patience… I literally have no idea how to make it editable so I’ve written to codepen support. As soon as I get my answer, I’ll repost.
So it looks like there is no option to have codepen projects editable without the user first forking it. From codepen team:
“Projects are different from Pens in that each Project runs in its own container that is read-only to everyone but the Project’s owner. To get an editable copy of your Project, another dev can fork the Project into their own account.”
So when it comes to sharing three.js stuff specifically, this is a big issue since any project requiring external resources can only be shared as a codepen project rather than a simple pen.
The only option currently is to fork the project…
Okay, I’ve boiled it down to just JS and created a simple pen, rather than a project. Any help would be appreciated! Reminder: uncomment line 193 to see the error. Thanks!
Working example: https://codepen.io/anon/pen/WYVOpq
Like I said before, it was a scoping issue. You should carefully study how
earth is created in the updated codepen.
Besides, it is
earth.rotation and not
You are a godsend, thank you. I’m still a student of JS and I appreciate the support. I’ll study the updates carefully. Thanks again!
Oh god, I’m such an idiot. It was a semantical error. Rotation not rotate. I’m just going to go cry in a hole now…