SP Ruby

Ruby?!

No, we're not giving you jewels! Ruby is an easy-to-learn programming language that can be used to create custom control scripts for Sketchyphysics. From basic formulas to a scripted differential, this lets you do what you want with the controllable joints, motors, emitters and magnets at your disposal. If you've used Ruby before, scroll down for some commands specific to SP.

Basic tutorial; for absolute beginners

(May need moving)

So, you'll want to know what commands you can use in those controller boxes, and, more to the point, how you'll fit a script in there! The single line boxes aren't perfect for this task, so if you're doing something really complex, I'd recommend typing it up in a word-processing program (Something like Notepad is perfect) and copying it across. For scripts, use ';' where you'd normally put a line break.

Formulas:


 * The most basic of basic, and this is where I'll start you off. Formulas are just a teeny weeny bit of maths; if you can put two and two together, you can write one... for example:


 * 2+2


 * See what I did there? Anyway, a formula is just a little bit of adding, subtracting, multiplying, dividing... etc. Of course, writing 2X2 doesn't mean anything to SP, so here are some of the symbols that you can use:


 * '+' Add
 * '-' Subtract
 * '*' Multiply
 * '/' Divide

(WIP)

Variables:


 * Variables are like boxes. Yes, boxes. They hold information for you, which you can take out, or swap with another piece of information... and, they will only be open if YOU open them! See? Like boxes.


 * To set a variable, use:


 * setVar("variable's name",information)


 * In most cases, the information will just be a number; technically, it'll always be a number, but it can be a rather special number, set using a button, joystick, or any of the other supported inputs. To retrieve the information you've put in it, use:


 * getVar("variable's name")


 * The clever thing about this is that you can retrieve it from somewhere outside of the controller box you created it in; so, you can set a variable in a hinge, but make it control the thrusters of 100 rockets! If you're in a hurry, and you want to both set AND get a variable at the same time (lazy), then use:


 * getSetVar("variable's name",information)


 * This is useful if you're changing a variable at the same time as you want to use it. Still with me? Good, because I'm about to hit you with the...

IF function:


 * if joy("lefty")<0.5; 1.0; else; 0.0; end


 * If you're staring at the screen, wondering why I hate you so much, let me tell you something... this is actually quite simple! All an if function does is ask if something's true or false. If it's true, it'll do one thing, if it's false... well, you get the idea. Here's a breakdown, in english, of what I wrote:


 * If left joystick's postion is below 0.5, set controller to 1. Otherwise, set it to 0. The end.


 * Now that wasn't so hard, was it? Here's the layout:


 * if question; answer true; else; answer false; end


 * Again, not so hard!

(WIP)

Sketchyphysics-specific Ruby

(WIP)