Just Beginning Love

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.
joshparrisjosh
Prole
Posts: 3
Joined: Mon Apr 20, 2009 5:27 pm

Just Beginning Love

Post by joshparrisjosh »

Okay, so I've been looking at trying to program with Love. I'm not new to programming in general. I have on okay background with C++ and I know pspLua. Anyway, to say the least, I am a little confused on the exact syntax and whatnot of Love. I've read through the documentation and the tutorials, however, I am still a little confused.

My primary question is, are all Love scripts written without a main loop? And is everything based off of the callbackfunctions?

My second question is, how is the Love script in the love file read by the interpreter?
For example:

Code: Select all

-- This is an empty program
function load()
end

function update(dt)
end

function draw()
end
From what I've read I know that the load function is only executed once. But everything thing else is executed multiple times? So what if I were to create my own function "function sum()" would this function be iterated just as often as the update() and draw() functions, or does Love have support for function calls?


And, finally where can I find more information about Config Files?
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: Just Beginning Love

Post by qubodup »

As far as I understand, update() is the main loop.

Config files: http://love2d.org/docs/ConfigFiles.html
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Just Beginning Love

Post by bartbes »

You're right that load gets called only once.
Update and draw are called every 'iteration', where draw is specific to drawing stuff, so you could call update the main loop.
Not all functions are automatically called, only update and draw (and other callbacks when their condition is met).
And yes, of course it supports function calls, it's lua, the GREATEST (yet small) language ever!! :ultrashocked::
OK, it's not the most powerful, but it's fast and easy. I know C, C++, PHP and a few others, but when I need to do something I'll use lua.
I'd suggest to get a feel for lua first. (or at least the syntax)
Alex
Prole
Posts: 30
Joined: Mon Mar 09, 2009 1:49 pm

Re: Just Beginning Love

Post by Alex »

Programming in Lua is a great read. It'll teach you Lua and give you a real appreciation of the language. I highly recommend that EVERYONE who hasn't already read it and is interested in love read at least the first three parts. If you're interested as to how Love is implemented, the source is the best place to look.
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: Just Beginning Love

Post by Xcmd »

To go over some of the finer points here:

Load is a function for loading things. HOWEVER, I don't recommend doing all your loading functions there, just your global loading functions since it's only called the one time. What I do is create a separate function called initVars() to initialize any variables I have that are going to need to be refreshed (such as resetting game values, etc). Load is called only the one time as has been mentioned before.

The primary difference between update() and draw() is that update includes an iterator variable that allows you to measure how long the application has been open since update was called the first time.

I may be very wrong here but I'm about 90% certain that Update is called before Draw, so if you need math and such done, it's best to do it over in Update and then have Draw simply refresh the screen.

I know it can be a tad confusing as regular Lua scrips (like Python) require you to make the last part of your code basically tell the application where to start. But! Here's a fun thing: anything BEFORE the load function gets read first. So if you define variables and such THERE instead of at LOAD, they'll still work.

But me, personally, I don't like doing that unless I absolutely positively have to do it to get the code to run right. Fun part about love is that it's an engine that takes well to tinkering and smacking around with a hammer. It's really more of a hobbyist engine than you're going to find elsewhere.

Now, if only I understood how file reading worked...
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Just Beginning Love

Post by bartbes »

Xcmd wrote:I may be very wrong here but I'm about 90% certain that Update is called before Draw, so if you need math and such done, it's best to do it over in Update and then have Draw simply refresh the screen.
Correct. (so make it 100% :P)
Xcmd wrote: I know it can be a tad confusing as regular Lua scrips (like Python) require you to make the last part of your code basically tell the application where to start. But! Here's a fun thing: anything BEFORE the load function gets read first. So if you define variables and such THERE instead of at LOAD, they'll still work.
Wrong. The entire file is executed before load() is called. This is simple the way lua works, by running the file the functions are defined. (they are declared just as variables would be declared)
Xcmd wrote: Now, if only I understood how file reading worked...
I already wrote a response to that..
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: Just Beginning Love

Post by Xcmd »

bartbes wrote:
Xcmd wrote:I may be very wrong here but I'm about 90% certain that Update is called before Draw, so if you need math and such done, it's best to do it over in Update and then have Draw simply refresh the screen.
Correct. (so make it 100% :P)
Okay, so I'm 100% certain, then.
bartbes wrote:
Xcmd wrote: I know it can be a tad confusing as regular Lua scrips (like Python) require you to make the last part of your code basically tell the application where to start. But! Here's a fun thing: anything BEFORE the load function gets read first. So if you define variables and such THERE instead of at LOAD, they'll still work.
Wrong. The entire file is executed before load() is called. This is simple the way lua works, by running the file the functions are defined. (they are declared just as variables would be declared)
I'm not really wrong so much as I'm not all the way right. What I said is technically true, but I didn't realize the rest of the file gets executed, too.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Just Beginning Love

Post by bartbes »

Xcmd wrote:I'm not really wrong so much as I'm not all the way right. What I said is technically true, but I didn't realize the rest of the file gets executed, too.
Yes, I was in doubt on what to put there.. anyway, let's get back on-topic.

@joshparrisjosh:
Did our posts help?
Nec
Prole
Posts: 1
Joined: Wed Apr 22, 2009 8:35 pm

Re: Just Beginning Love

Post by Nec »

Im new to Lua and Love (I figure why not try my hand at some Lua). Im not knew to programming, though. Im a Java programmer and Ive got to say that these posts helped quite a bit. Ive just got to get used to the way Lua goes about things (no curly braces :()
joshparrisjosh
Prole
Posts: 3
Joined: Mon Apr 20, 2009 5:27 pm

Re: Just Beginning Love

Post by joshparrisjosh »

Yeah. Thanks a lot your guys posts really clarified a few things for me.

I guess I'm still trying to wrap my head around this new way of doing things, for example, I'm used to dealing with pspLua it seems strange that something like this wouldn't work.

Code: Select all


function draw()
draw code
end

while true do 
        draw()
end


Why doesn't this work, by the way?



Also is all that there is on config files http://love2d.org/docs/ConfigFiles.html?
title The game title.
author The author of the game.
width Display resolution width.
height Display resolution height.
fullscreen True if fullscreen, false otherwise.
vsync True if attemt to enable, false otherwise.
fsaa Number of FSAA-buffers.
display_auto Set this to false if you want to configure the display in Lua manually.
love_version The LOVE-version this game was made for.
I mean the parameters for the most part makes sense, but I can't seem to get them to do what I want at all.
How does I change the screen resolution. This probably sounds dumb but I can't get it to change no matter what I type. Ist there a specific way that this is done?
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 47 guests