Hi, I was wondering if someone could explain this code from the manual for converting the cos and sin functions into ones which use radiens rather than gradiens and uninvert sin.
cos1 = cos function cos(angle) return cos1(angle/(3.1415*2)) end sin1 = sin function sin(angle) return sin1(-angle/(3.1415*2)) end |
I understand the maths elements it's more just the lua syntax here. And does this replace the functionality of sin and cos or add new functions cos1 and sin1 with the new functionality?
Many thanks
It might help to split it up:
cos1 = cos |
Copies cos() to cos1()
function cos(angle) return cos1(angle/(3.1415*2)) end |
Now that cos() has been copied, we can safely override the standard functionality. We use the old cos (now cos1) to convert to radians.
I have no idea why the two lines they can be squished to fit one line.
And to answer your question: Yes; this replaces the standard cos() and sin()
lua doesn't actually need line separators or semicolons (usually) because its syntax is designed so that it's unambiguous (usually) when one statement ends and the next begins. line breaks are for the benefit of human readers.
you can read more about lua's syntax in section 3 of the lua manual. you can find specific mention of the only (as far as i'm aware) ambiguity in section 3.3.1.
@helado oh, i wasn't aware of that. Only just learned lua for Pico 8. That explains quite a lot of what i thought was weird one-of syntax.
[Please log in to post a comment]