Custom functions

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.
Post Reply
User avatar
Lazy Waffle
Prole
Posts: 5
Joined: Sat Nov 28, 2009 11:26 pm
Location: Somewhere

Custom functions

Post by Lazy Waffle »

Is it possible to make my own functions? It's just to shorten certain things (find the distance between 2 sets of coordinates, etc.)
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Custom functions

Post by TechnoCat »

Of course!

Code: Select all

function love.load()
   local x, y, dis
   x = 10
   y = 5
   dis = math.sqrt(math.pow(x,2)+math.pow(y,2))
end
Is the same as

Code: Select all

function love.load()
   local dis
   dis = distance(10,5)
end

--Finds the distance from the origin to an (x,y) point.
function distance(x, y)
   return math.sqrt(math.pow(x,2)+math.pow(y,2))
end
I didn't actually test my distance function, but you probably get the function idea. :megagrin:
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 77 guests