• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Using formulas

Scheduled Pinned Locked Moved SketchyPhysics
18 Posts 4 Posters 2.1k Views 4 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    Alienizer
    last edited by 26 Mar 2009, 21:40

    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?

    I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

    1 Reply Last reply Reply Quote 0
    • P Offline
      Physicsguy1
      last edited by 26 Mar 2009, 21:53

      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"

      1 Reply Last reply Reply Quote 0
      • P Offline
        Physicsguy1
        last edited by 26 Mar 2009, 21:57

        You can alos, in the place of righty, in the previous post, put in:

        (key("space"))
        

        , or any letter on the keyboard, including shift.

        1 Reply Last reply Reply Quote 0
        • A Offline
          Alienizer
          last edited by 26 Mar 2009, 22:12

          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!!

          I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

          1 Reply Last reply Reply Quote 0
          • P Offline
            Physicsguy1
            last edited by 26 Mar 2009, 22:15

            umm. Put it in any field like strength or rate

            1 Reply Last reply Reply Quote 0
            • A Offline
              Alienizer
              last edited by 26 Mar 2009, 22:35

              @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.

              I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

              1 Reply Last reply Reply Quote 0
              • W Offline
                Wacov
                last edited by 26 Mar 2009, 22:41

                Whoa, slow down. The blue fields are the ones that can use code...

                http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                1 Reply Last reply Reply Quote 0
                • A Offline
                  Alienizer
                  last edited by 26 Mar 2009, 22:44

                  @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?

                  I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                  1 Reply Last reply Reply Quote 0
                  • P Offline
                    Physicsguy1
                    last edited by 26 Mar 2009, 22:52

                    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

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Alienizer
                      last edited by 26 Mar 2009, 23:05

                      ok thanks again for the help. Do you know where I can find the "codes" we can enter?

                      I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                      1 Reply Last reply Reply Quote 0
                      • W Offline
                        Wacov
                        last edited by 27 Mar 2009, 16:54

                        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.

                        http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          Alienizer
                          last edited by 27 Mar 2009, 22:15

                          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.

                          I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                          1 Reply Last reply Reply Quote 0
                          • C Offline
                            CPhillips
                            last edited by 27 Mar 2009, 23:53

                            Its all Ruby syntax. So anything that is legal Ruby should work.
                            http://web.njit.edu/all_topics/Prog_Lang_Docs/html/ruby/syntax.html

                            Sin is Math.sin()

                            The SP specific keywords are not fully documented yet. My top priority.

                            1 Reply Last reply Reply Quote 0
                            • W Offline
                              Wacov
                              last edited by 28 Mar 2009, 10:45

                              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.

                              http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                              1 Reply Last reply Reply Quote 0
                              • A Offline
                                Alienizer
                                last edited by 29 Mar 2009, 02:20

                                Perfect 👍 Thank you guys 😍

                                I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                                1 Reply Last reply Reply Quote 0
                                • W Offline
                                  Wacov
                                  last edited by 29 Mar 2009, 19:07

                                  Oh, don't forget setVar("var") and getVar("var"). This creates and retrieves global variables that carry between frames.

                                  http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                                  1 Reply Last reply Reply Quote 0
                                  • A Offline
                                    Alienizer
                                    last edited by 30 Mar 2009, 00:08

                                    @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.

                                    I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                                    1 Reply Last reply Reply Quote 0
                                    • C Offline
                                      CPhillips
                                      last edited by 30 Mar 2009, 01:35

                                      One other variable function is

                                      
                                      #get the var foo and set it to 0
                                      v=getSetVar("foo",0)
                                      

                                      It can be a useful shortcut.

                                      1 Reply Last reply Reply Quote 0
                                      • 1 / 1
                                      1 / 1
                                      • First post
                                        6/18
                                        Last post
                                      Buy SketchPlus
                                      Buy SUbD
                                      Buy WrapR
                                      Buy eBook
                                      Buy Modelur
                                      Buy Vertex Tools
                                      Buy SketchCuisine
                                      Buy FormFonts

                                      Advertisement