My ongoing newbie questions

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
essell
Prole
Posts: 15
Joined: Tue Jun 09, 2009 6:26 pm
Location: Newcastle, UK
Contact:

Re: My ongoing newbie questions

Post by essell »

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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: My ongoing newbie questions

Post by bartbes »

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')
essell
Prole
Posts: 15
Joined: Tue Jun 09, 2009 6:26 pm
Location: Newcastle, UK
Contact:

Re: My ongoing newbie questions

Post by essell »

That's what I suspected. Cheers :)
User avatar
ljdp
Party member
Posts: 209
Joined: Sat Jan 03, 2009 1:04 pm
Contact:

Re: My ongoing newbie questions

Post by ljdp »

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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: My ongoing newbie questions

Post by bartbes »

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)
essell
Prole
Posts: 15
Joined: Tue Jun 09, 2009 6:26 pm
Location: Newcastle, UK
Contact:

Re: My ongoing newbie questions

Post by essell »

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?
User avatar
Jake
Prole
Posts: 27
Joined: Sun Jul 20, 2008 2:01 pm

Re: My ongoing newbie questions

Post by Jake »

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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: My ongoing newbie questions

Post by bartbes »

Yes, that works, I'll warn you math.floor isn't the most effective function in lua though, btw you forgot something like:

Code: Select all

function math.round(n, dec) --dec = decimals
    dec = 10^(dec or 0)
    return math.floor(n*dec+0.5)/dec
end
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: :ehem:
Last edited by bartbes on Fri Jun 12, 2009 12:50 pm, edited 4 times in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: My ongoing newbie questions

Post by Robin »

That doesn't work: firstly, s/x/n, secondly, /s/dev/dec.

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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: My ongoing newbie questions

Post by bartbes »

I edited my post, thx Robin
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests