Some of that's getting a bit over my head to be honest Will look into it further down the line though - I'm told by my programmer mate that I should learn to use tables soon. Cheers.
Q. When there's a bug and my game won't run, I often get '<eof>' expected near 'end' as the error. What does this mean, generally?
My ongoing newbie questions
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: My ongoing newbie questions
I guess it means that there is one 'end' too much in your code, so you're exiting code blocks more often than entering them. (that sounds complicated, simple is: too much 'end')
Re: My ongoing newbie questions
That's what I suspected. Cheers
Re: My ongoing newbie questions
You might already know about this but i
recommend you have good read of this
http://www.lua.org/pil/
Don't just read it too, have whatever you code in open next to it too
and type in all the examples by hand start experimenting simply with them.
It helps tremendously when learning a computer language.
recommend you have good read of this
http://www.lua.org/pil/
Don't just read it too, have whatever you code in open next to it too
and type in all the examples by hand start experimenting simply with them.
It helps tremendously when learning a computer language.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: My ongoing newbie questions
Never used it, I always stick with the reference manual (but then again, I already was a programmer before starting with lua, it was a small syntax switch)
Re: My ongoing newbie questions
Aye a friend linked me to that too - will start dipping into it
Q. How do I take a float and convert / round it to the closest integer?
Q. How do I take a float and convert / round it to the closest integer?
Re: My ongoing newbie questions
I don't think Lua has a round function but this will do the same
Code: Select all
function math.round(x)
return math.floor(x+0.5)
end
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: My ongoing newbie questions
Yes, that works, I'll warn you math.floor isn't the most effective function in lua though, btw you forgot something like:
Haven't tested this, but should allow you to set how accurate it is, so, if you set dec to 1, it will give you 1 decimal.
EDIT: Robin was right.. made a typo
EDIT2: and, of course, robin was right again, it's 10^dec
EDIT3:
Code: Select all
function math.round(n, dec) --dec = decimals
dec = 10^(dec or 0)
return math.floor(n*dec+0.5)/dec
end
EDIT: Robin was right.. made a typo
EDIT2: and, of course, robin was right again, it's 10^dec
EDIT3:
Last edited by bartbes on Fri Jun 12, 2009 12:50 pm, edited 4 times in total.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: My ongoing newbie questions
That doesn't work: firstly, s/x/n, secondly, /s/dev/dec.
EDIT: thirdly: still doesn't work.
EDIT2: this works:
EDIT: thirdly: still doesn't work.
EDIT2: this works:
Code: Select all
function math.round(n, dec) --dec = decimals
dec = 10^(dec or 0)
return math.floor(n*dec+0.5)/dec
end
Help us help you: attach a .love.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: My ongoing newbie questions
I edited my post, thx Robin
Who is online
Users browsing this forum: No registered users and 0 guests