Using formulas
-
I keep seeing posts about using formulas, scripts and stuff. Do they mean to modify a .rb file? because I can't find anywhere to enter formulas or anything in the UI! or am I stupid?
-
If you can use Sketchyphysics, i wouldn't consider you stupid. It is either 1.) you have to select an object, or 2.)you have to select a joint. Formulas are typed in the fields on the UI. Here is an example for a thruster.
-(0.5-righty)*50
this will thrust at 50 when you press either the up arrow key or the down key. Locate this code yourself into the strength field of a thruster, and check "thruster"
-
You can alos, in the place of righty, in the previous post, put in:
(key("space"))
, or any letter on the keyboard, including shift.
-
Thanks to clarify, I appreciate it. But I see no "Code" field when I select an object or a joint! I see "Joint", "State", "Properties" and "Shapes". That's where I'm stupid. I can use Sketchyphysics very well, but can't find the "Code" field!!
-
umm. Put it in any field like strength or rate
-
@unknownuser said:
umm. Put it in any field like strength or rate
oh!! You mean the fields that we put numbers in? Like "maxAccel" for the motor? duh! I thought only numbers were accepted. Now that make sense. But where do I find those code like (key("space")) like your example? Any documentation anywhere?
Thanks for helping.
-
Whoa, slow down. The blue fields are the ones that can use code...
-
@wacov said:
Whoa, slow down. The blue fields are the ones that can use code...
I got all excited here didn't I
Can you enter more than one line in the Blue field? What's "Code: Select all" I see in both of your examples?
-
oh no. that will select it all if you click on it. That will help copy the formula so you can paste it in the fields
-
ok thanks again for the help. Do you know where I can find the "codes" we can enter?
-
Scripting is kind of up to you; what you want is to end up with a value, which is what the joint/thruster/emitter/magnet/whatever will be set to. Scripts run each frame of the simulation, so if something changes, like an input from a joystick, then the script will update using this new input. The codes do logical calculations, putting them together, changing them and making them do what you want is up to you; a basic understanding of algebra will help. Search through the forums for the specifics, but there are 'if' functions, which do a test and give a value for either true or false. 'if, elsif' functions do a new test if the first one was false. There is a script that will cycle through values based on the frame number, and there are little snippets which do nice, easy to understand stuff like '0.5-lefty', which, on a motor, allows reversable control using lefty, which is w,s or the left joystick's up/down.
-
Thank you Wacov. I'm a Delphi programmer so I'll have no problem with little functions. What I meant to ask was, where do I find the "keywords" that the blue fields understand. There is the "if,else" but is there any "not,and,or,xor", there is "lefty, leftx" but what about other ones? What about math like sin, cos etc? and of course, things like +-* (/ or \ or both?) what about =, ==, === which is used? bla bla bla. you know! Or maybe I'm looking too hard, is it a ruby script we enter? and all ruby functions will work? Sorry for my ignorance.
-
Its all Ruby syntax. So anything that is legal Ruby should work.
http://web.njit.edu/all_topics/Prog_Lang_Docs/html/ruby/syntax.htmlSin is Math.sin()
The SP specific keywords are not fully documented yet. My top priority.
-
Some useful stuff (in the new syntax):
joy("leftx")
joy("lefty")
joy("rightx")
joy("righty")
joyRY (Analogue triggers on a 360 style pad)joybutton("a,b,x,y,rb,lb")
key("q,w,e,r,t,y,etc")All the buttons work through joystick emulation, with off being 0.0 and on 1.0. leftx and y are also w,a,s,d on the keyboard, rightx and y are the arrow buttons.
-
Perfect Thank you guys
-
Oh, don't forget setVar("var") and getVar("var"). This creates and retrieves global variables that carry between frames.
-
@wacov said:
Oh, don't forget setVar("var") and getVar("var"). This creates and retrieves global variables that carry between frames.
This will be very handy, thank you.
-
One other variable function is
#get the var foo and set it to 0 v=getSetVar("foo",0)
It can be a useful shortcut.
Advertisement