Scripting Test
Jan 20, 2015
This might not seem very impressive, but it represents a major milestone in Thimbleweed Park. If you're not impressed, at least pretend you are. My feelings get hurt pretty easy.
I'm looking at using Squirrel as the scripting language for Thimbleweed Park and one of the things I always liked about SCUMM was how it handled multi-tasking. It was effortless to run scripts in different threads and let objects handle themselves without cumbersome state engines or weird co-routines.
I just want to start a function and have it run until told otherwise. I've seen a few scripting languages that can do this, but Squirrel didn't have the ability "out of the box".
I was chatting with my friend Vincent Hamm (who worked on SCUMMVM in the early days) and he didn't think it would be too hard, so he whipped up a quick proof of concept.
The true test of a game scripting language is being able to do powerful things with very little code.
I spent the few days last week getting his code integrated into my engine and started to implement all the bindings between Squirrel and my code.
I wrote the following Squire code that drives the video above.
{
local image = Image("GameSheet", imageName);
local x = random(0, 1280);
local y = random(0, 720);
do
{
local steps = random(100.0,150.0);
local end_x = random(0, 1280);
local end_y = random(0, 720);
local dx = (end_x - x) / steps;
local dy = (end_y - y) / steps;
for (local i = 0; i < steps; i++)
{
x += dx;
y += dy;
image.at(x, y);
breakhere(1);
}
}
while(1);
}
for (local count = 1; count <= 10; count++)
{
startthread(bounceImage, "Detective1");
}
for (local count = 1; count <= 10; count++)
{
startthread(bounceImage, "Detective2");
}
Over the weekend, I started to create the structure of a "room" and figuring out how the scripting will interact with all the objects, characters and verbs. I should have that working by the end of the week and will do another post with some more glorious code. I know everyone lives to see source code.
There is still a long ways to go before it looks like an adventure game, but believe it or not, this is a big step forward. It's pretty much just polish from here on out.
- Ron
Coding help from old friends. What could be better.
But please, tell me that no detectives were harmed in the making of this test. Some of them go through the others like Patrick Swayze in Ghost. That hurts!
myThread = startthread(bounceImage, "Detective1");
...then at some later point, you do a...
stopthread myThread
(don't move low-res characters in high-res steps :-)
I'm really looking forward to the end result!
I remember reading somewhere about early SCUMM and how there were processes that executed independently of one another and me thinking "BLIMEY THAT SOUNDS A LOT LIKE A KERNEL! SCUMM IS ESSENTIALLY AN OS!" Inspired the design of my own forays!
For Thimbleweed did you implement your threads as real process threads (provided by the underlying operating system) or did you do your own thread-like implementation again?
startthread -> StartCoroutine
stopthread -> StopCoroutine
breakhere(1) -> yield return null;
breakhere(n) -> for (int i=0;i<n; ++i) yield return null;
breaktime(t) -> yield return WaitForSeconds(t);
function return -> coroutine's end
coroutine deadlock -> game and editor deadlock (lol)
Thanks for the explanation!
For the sake of it, I propose you to try Go language. It is also compiled, and it has great concurrency with channels etc.
Lua however has a bigger community and could be a better choice for the future, especially with new requirements like concurrency etc.
He never mention them, but we can imagine he also played the same games created by Ron, Gary and company.
So, Squirrel derived from the games that Ron created, and now Ron is creating a game using Squirrel, that has been created by a game created by Ron...
Maybe the cat on the bread slice paradox is simpler!!!
The scripting language looks simple, but personally I would have preferred to get rid of some of the noise. E.g. the local keyword for variable declarations, semicolons after statements, and parentheses for method calls. On the other hand the language seems like a very reasonable choice for keeping the development effort down.
http://www.irrelevantconclusion.com/2012/01/latent-functions-for-squirrel/
Just for whom do not understand anything about programming...or almost anything..
Is this the game engine then?.
Is this the game engine?
For example, if Ron writes a script where the Detective has to move from the corpse location to the bench, and while this action is completing another script is launched (for example, to move the clown to jump on a tree), the Detective should not stop, but continue to move.
All that stuff is not ever so easy to do, and this test demonstrates that not only it's possible, but also quite easy to manage.
is this the answer to my question or just a consideration?
Now whats finally missing here (what has he ever done to you?) is that you pretend that you are very impressed indeed! :)
By the way, why is the answer to the seckrit question always so hard?
Are you using raw squirrel for binding, or a bindings library such as Sqrat?
One question: I know that Squirrel is a high-level scripting language that should speed up things, but why didn't you code your own specific one like SCUMM? I know it sounds like reinventing the wheel, but I remember you saying how fast and easy was adding features and behaviors to the game with SCUMM. How will you achieve the same goal with Squirrel?
I.e. I divide the fractional dx, dy by two (so its just shifting) until their sum is <= 1 and as I shifted a counter in parallel I always know how many steps to take. As far as I know Maniac Mansion on C64 didnt use fractional dx,dy but went for the direction with the largest delta.
Running scripts on a per-frame basis in dedicated slots back then was amazing and I happily copied that approach : )
My scripts run themselves repeatedly with on data or are capable to replace themselves, i.e. a walking-to script after an find-proper-path-to-target script. Yes, I am just bragging but it soo much fun :)
Will you implement something similar to the walking-boxes and pre-calced Dijkstra or rather some real-time pathfinding?
You shouldn't change anything because it's good as it was and quite funny to look at.
I have a question: I know it is just a tech demo, but if this were real, you'd have to allocate images in the main thread and pass a reference to the animation thread, otherwise an image, which is thread local would be deleted once the thread is dead. Also you will have to care of locking (mutex), if you use resources across threads. Do you guys need to extend squirrel to be able to understand these things?
Regards,
Pedram
The code in C# looks about identical but is bit shorter and of course less typing with auto-completion.
I would probably implement the game to run completely in browser from server side. Then draft up some legal doc that if someone buys up the company or it goes bust, the buyers get the server code ... if archive.org is running old games in dosbox that was compiled to javascript, surely there's a way to run C# cross platform in browsers too. I just haven't heard of it yet.
Why is this important? Well if I were to buy a game, I don't like it if someone can have it for free (I'd rather have free high quality demos than the paid alpha tests of these days, like back in the 90s). If someone can have it for free, then that may effect the resale value of the physical box, which is bad from investment perspective. To furher increase the value of the boxed version, the boxed edition buyers should get something special in the browser version through use of uncrackable license code (thanks to the game running in unhackable server, thanks to not using C++). Perhaps a unique room full of boxed games? LOL
If I voted a comment or idea down by agreeing on some critique posted by someone else, then the original poster could post a rebuttal to the critique and invalidate my vote. That would be mighty annoying as then as a perfectionist I'd have desire to answer to that rebuttal. In urban dictionary this is atleast under "tireless rebutter", one who wants to have the last word.
Possible solution to this is that all negative votes (eg. agreed on a critique) are final on version basis - after revision only few votes against the critiques would put those into invalidated state. This should reduce the endless arguments and rebuttals issue to minimum, especially with multiple votes on castable on different critiques, allowing the revision to address all the issues quickly.
than producing a bullet-proof perfect-utopistic comment system :/
Or is there a more elegant way of doing this .
I guess one of the reasons Squirrel is not used more often is because of the lack of tools.
I'm at the moment refactoring the IDE I've made for another project, to be a dedicated Squirrel IDE, with nice syntax colouring, debugger and all.
I should have something usable in the next few days, as I'm just bringing code from the other project and adding what I need for Squirrel.
Feel free to provide to suggest features. :)
Repository at: https://bitbucket.org/ruifig/nutcracker
* Game logic becomes much more linear and easy to follow.