Improving development cycle

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
hlship
Prole
Posts: 11
Joined: Mon Dec 05, 2011 8:39 pm

Improving development cycle

Post by hlship »

I'm quite new to Love2D development but I'm having a touch of fun.

I'm used to developing with a REPL (in Clojure or ClojureScript), so I'm kind of used to starting a system and tinkering with it while it runs.

It would be great if love.app (I'm on Mac) had an option that would let it live-reload the game if it changes ... ideally, maintaining state but even just restarting would be nicer. I know there are some add-ons for this, but they are a bit limited and intrusive; this feels like something that could be done by Love itself more efficiently.

In addition, I'm developing in Fennel and generating .lua from that; I have a Makefile to hang it all together but its not ideal ... stack traces show mangled names. The Fennel folks are chatting about generating JavaScript style source maps and it would be outstanding if Love would take those into account when loading code.

I continue to be impressed by, and even daunted by, the great things put together by the community. I'm still making baby steps.
snowcat
Prole
Posts: 5
Joined: Thu Apr 19, 2018 2:56 pm

Re: Improving development cycle

Post by snowcat »

Maintaining state perfectly across reloads is nearly impossible if you don't cooperate and write your code in a specific way. I don't know Fennel but I'd imagine functional programming in lua being close to the worst case, since anonymous generated functions are one of the biggest problems for hot reloading. OOP is terrible too, but at least you can write your classes in a way that allows hot reloading your base classes by simply loading the file again. You can't generally do that for anonymous functions that are being passed around.

You can call love.event.quit("restart") to restart love. Doesn't preserve state of course, but if the add-ons are too intrusive, maybe you can just put a button somewhere that calls this. That's what I like to do.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Improving development cycle

Post by raidho36 »

The kind of live-reloading you want is only good for tweaking the settings, something you can accomplish with a little bit of debug menus. It will absolutely fail if you make some actual change to the source code, your only option there is to reload the whole thing.

I would recommend that you just develop in Lua, it's a perfectly capable language. It's the single most popular game scripting engine and there are a lot of good reasons for that.
hlship
Prole
Posts: 11
Joined: Mon Dec 05, 2011 8:39 pm

Re: Improving development cycle

Post by hlship »

I've actually switched from Fennel to straight Lua - I prefer Lisp syntax, but without the rest of Clojure idioms and tools, it wasn't worth it.

I suspect that, by creating a state module used by other modules, I can hit my goal of being able to make minor changes while the game is running (because the code modules will change, but the state module will not).
snowcat
Prole
Posts: 5
Joined: Thu Apr 19, 2018 2:56 pm

Re: Improving development cycle

Post by snowcat »

Firstly, if you're still looking for how to load a file (or reload - same thing!), check out love.filesystem.load.

You don't actually need very strict separation, you just need to avoid resetting your state on load. E.g. this counter will reset on reload:

Code: Select all

count = 5
function countDown()
	count = count - 1
	return count
end
This one will not reset:

Code: Select all

count = count or 5
function countDown()
	count = count - 1
	return count
end
Note that in lua, only false and nil evaluate to false in boolean expressions. If count is 0 at load time, it will remain 0 here.


Another thing to be aware of is that anonymous functions generally can't be reloaded. E.g. this slightly buggy code is hard to repair completely with a reload:

Code: Select all

function make_multiplier(x)
    return function(y) return x + y end
end
After changing the operator to *, reloading the file make_multiplier() is defined in will fix make_multiplier(). But it won't fix any existing instances of the function it returns.


Btw. I disagree with the idea that reloading is only good for tweaking settings. It depends on the project's structure. My current project uses an object oriented UI, and my goal is some reasonable degree of live coding ability. I'm not quite there yet, but here's an example of what it does when I inject an intentional bug (crash when the user types "." in the editor):

https://gfycat.com/DelightfulCompassionateGroundbeetle
Post Reply

Who is online

Users browsing this forum: No registered users and 97 guests