3 ms·
It's hard to write game in a language without side effects, even if you don't care about performance. Games are made in iterative process, you change sth, test
by ajuc 13y ago
It's hard to write game in a language without side effects, even if you don't care about performance.
Games are made in iterative process, you change sth, test, etc. You don't know if something is fun and looks good without testing it. And it's really hard to upfront design for fun.
Without side effects most of the time programming in this way is spent maintaining long arguments lists and passing them around to be able to add even very small features.
You want to play sound when player leveled up? Pass soundManager through this 7-functions-long callstack. Now you also want to shoot stars around the player on the occassion? Pass this ParticleEffect handle too. Oh, but the effects should vary depending on the region the player is in? Pass that information to that function too. And time of the day, while you're at it, so stars can be blue at night and yellow at day.
In the end you give up and pass WorldState variable to every function. I don't think pure functional programming is good for prototyping games.
I thought about this problem a little, and I think this could be solved by structuring the WorldState variable into a tree, and writing a script that you run after the game is done, that looks inside functions for which parts of the WorldState they really need, and changing them accordingly, so the code is easy to read and functional after the experiments are done.
- cgag 13y agoJust for the record, Clojure has a good system for managing mutable state when you need it, of course has java interop so there's nothing from stopping you from mutating java objects. Edit: Here's a guys experiences from making a game in Clojure a year ago: http://stackoverflow.com/questions/9755882/are-functional-programming-languages-suitable-for-graphics-programming http://stackoverflow.com/questions/9755882/are-functional-pr... http://clojurefun.wordpress.com/2012/09/03/ironclad-steam-legions-clojure-game-development-battle-report/ http://clojurefun.wordpress.com/2012/09/03/ironclad-steam-le...
- ajuc 13y agoThanks for the links, very interesting. I see the guy behind this had the same problem: > Long parameter lists – I struggled a bit with this, and still don’t have a great solution.