It's not complete, and it can cause odd crashes in the editor from time to time, but here's what I have so far.
Here are some examples of working Lua scripts:
mzx.star('Hello world!');
while true do
mzx.go('n', 2);
mzx.go('s', 2);
mzx.wait();
end
function when.touch()
mzx.star('Hello!');
mzx.char(string.byte('X'));
end
while true do
mzx.slash('nneessww');
end
function when.dance()
mzx.slash('wwweee');
mzx.send('Righty', 'dance');
end
when.dance();
mzx.sleep();
---
function when.dance()
mzx.slash('eeewww');
mzx.send('Lefty', 'dance');
end
mzx.sleep();
function when.playershot()
mzx.color(0xc2);
mzx.star('OKAY, I GET THE POINT. I NEED MORE IRON');
when.playershot = function()
mzx.star('...cut it out. =(');
end
end
function when.bombed()
-- Check this out...
-- (editor) I'm not impressed.
mzx.star('ARRGHFRRAGGH I\'M ALLERGIC TO BEING BOMBED');
mzx.die();
end
function when.touch()
mzx.star('Watch out!');
mzx.wait(10);
mzx.shoot('NORTH');
end
mzx.sleep();To embed Lua in your robots, write each Lua line as a separate comment, and begin the whole block with a ". #!lua" line. That is, "#!lua" in a comment. Robots can be executing in Robotic or Lua mode, depending on the value of the special Robot-specific counter INTERP (0 = Robotic, 1 = Lua). So to run Lua in a robot, you'd do this:
set "INTERP" to "1"
. "#!lua"
. "mzx.star('Hello world!');"
. "mzx.sleep();"The final mzx.sleep(); is there to prevent the Lua interpreter from falling off the end, which will automatically revert the robot to Robotic state. Of course, you could do this intentionally if you wanted to.
Saving and restoring works as expected. The Lua environment and every robot are saved into the .SAV files. They are incompatible with other versions of MZX. This depends on the Pluto library to work, which is a lightweight (~1500 line) library that adds save states to Lua, basically.
Many operations aren't available in Lua mode at the moment. Robotic and Lua code should also be able to interact more. You should (emphasis on should) be able to exit Lua mode by doing mzx.set('INTERP', 0), but this is completely untested. You can, however, send messages to other robots that are executing in Lua mode, and they can receive them. Just define a function "when.X()" to handle message X, as you can see above.
In order to compile this, you'll need Lua 5.1, Pluto 2.4 (for saved games), and MZX 2.81h. You'll need to apply the patches here:
http://home.uchicago...-patches.tar.gz
You must apply the patch to Pluto. It contains bug fixes to Pluto that will segfault MZX if you don't apply it. If you don't know how to apply patches, then this release is not for you anyway.
Have fun... feel free to ask any questions.

Help











