My brother and I are huge fans of Lisp, and we decided to give implementing BiwaScheme into PlayCanvas a shot!
A couple things could probably be handled better, for example although we initially intended for you to use schemeRunner.js for all of your game objects, we realized a little too late that this didn’t create much flexibility in running multiple Scheme files on one object, as well as the handy feature of dragging and dropping assets onto a script’s attributes, so we kind of took the lazy way out of both of those problems and just created duplicates of the same runner script with the attributes we needed.
It works though! We re-wrote the entire example ball game in BiwaScheme for you guys to get an idea of the workflow if you’re interested!
Feel free to ask questions or make any improvements as you see fit!
I think by far the most commented Scheme script is teleportable.scm, so I would look at that first. The original scripts are also there for you to compare and contrast. They’re mostly one to one, although we got rid of the “to” and “from” variables in teleport. We could add those in pretty easily, but I think it’s pretty obvious how to go about it from the rest of the code anyway.
Thanks for reading!
Comes with a single schemeCacher.js file that you can use to define the script names and attributes necessary for your SCM file.
This is great, congrats! I also love functional languages, though don’t get much time to use it in practice.
Did you consider using a scheme->js cross-compile approach instead of interpreter? Is it possible? I wonder if compiling the scheme sources to JS would give you the benefits of using a functional language, but still run quickly and also integrate more easily into the existing playcanvas framework?
Looking at your example, you could simplify things by moving the initialize() and update() functions in runner/runnerCamera/runnerMovement to their own script (for example scheme.js). Then you could just call the functions from the scripts that need it (passing in this). You would have to make sure scheme.js is loaded first in the scene settings panel, but with this in place adding new entities should be quite simple. Just call SchemeInitialize(this) (or whatever you call the function) and SchemeUpdate(this).
You know, I decided to give those “SchemeInitialize” and “SchemeUpdate” functions a shot and for some reason having it as a static function in scheme.js is making it lose scope half-way through evaluating it.
Mid-way through the script it throws the error that “txt.replace”, one of BiwaScheme’s internal functions, is not defined.
Not really sure why that is, since the interpreter is already defined by using the BiwaScheme static and making it a new BiwaScheme interpreter class, it itself is the object calling the evaluate function.
I’ll keep trying some different things. Thank you for the suggestions!
Thank you, that’s pretty cool! I gotta find a way to have it run that script automatically, it’s nicer than copying and pasting between the text editor.
I think you were thinking more along the lines of having the scheme.js file add it to a kind of conglomerate script at run-time so that init and updates are all done at once, but the way I handled a lot of problems is still pretty object oriented, so although they all call the same static functions for interpretation, they’re assigned back to the gameobjects after processing.
My brother and I have been using R3 pretty extensively for a new game project, and we’re pretty happy with the workflow! If you’re looking to enter a Lisp gamejam or just learn the language in general, give it a try!
We recently wrote an FPS controller with mouse look, jumping, and crouching!