sketchucation logo sketchucation
    • Login
    1. Home
    2. klaufi
    3. Topics
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    K
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 19
    • Groups 1

    Topics

    • K

      Error: undefined method '+' for nil:NilClass

      Watching Ignoring Scheduled Pinned Locked Moved SketchyPhysics
      3
      0 Votes
      3 Posts
      3k Views
      K
      Ok, now this works. Now I have another problem: I can't read out the frame in the scripted box. if i do so, an error message appears. When I write something like Math.sin(frame/100.00) in the controller of a servo, it works, but if I write setVar("a",frame/100.00) and into the controller getVar("a") the error message occurs. That's really odd... edit: It seems, that my old SP models work well, but if I copy the code into a new Scripted-box ob an object, it doesn't work anymore. Maybe I should get an older Version of SP?
    • K

      Programming a Robot Arm

      Watching Ignoring Scheduled Pinned Locked Moved SketchyPhysics
      11
      0 Votes
      11 Posts
      1k Views
      S
      Hi Klaufi, I have altered your code a little bit to use arrays for value and the new code illustrates various ways to iterate through, change and print out the the contents of an array. I think you will find the methods useful if your project gets more complex. I have also introduced a "case" construct for the counter, so that that the "move" procedure is not called 5 times every frame, which might speed things up a little. I hope you find the new code informative. Took me while to figure out how to do it, but it is all helping me learn Ruby. I just hope the Ruby etiquette police do not find out we have been using global variables. See the attached SU6 file but just in case that does not work, here is the code: def getf(frm) frm end f=getf(frame) if f==0 $temp=0 $counter=1;$counter2=0 $value=[0.5,0.5,0.5] $istpos=[0.5,0.5,0.5] end def move(zeit,sollpos,f) if f>=$temp && f<=zeit+$temp; if $counter != $counter2 # Only print to console if counter changes. puts "$counter= #{$counter} zeit= #{zeit} sollpos= #{sollpos.inspect} frame= #{f} " for i in (0..$value.length-1) # one way to iterate through array and print contents. puts "$value[#{i}]= #{$value[i]} " end $counter2 = $counter end $value.each_with_index { |i,j| $value[j]=$istpos[j]+(sollpos[j]-$istpos[j])*(f-$temp)/zeit; } # Another way to iterate through an array. end if f==zeit+$temp+1 $temp=$temp+zeit $counter=$counter+1 $istpos=sollpos puts"$counter=#{$counter} $temp=#{$temp} " puts"$istpos= #{$istpos.inspect} " #quick way to print array contents. end end case $counter when 1 move(150.00,[1,0.3,0.1],f) when 2 move(300.00,[0,0.1,0.2],f) when 3 move(20.00,[1,0.8,1],f) when 4 move(500.00,[1.5,0.9,0.6],f) when 5 move(20.00,[0,0.3,0.2],f) when 6 puts "Programmed sequence ended." $counter+=1 else # do nothing end atest2_SU6.skp
    • K

      On Tick?

      Watching Ignoring Scheduled Pinned Locked Moved SketchyPhysics
      3
      0 Votes
      3 Posts
      483 Views
      B
      ... But make sure to set the onTick framerate to 2
    • K

      Gearshifting with Variables?

      Watching Ignoring Scheduled Pinned Locked Moved SketchyPhysics
      4
      0 Votes
      4 Posts
      462 Views
      K
      thanks but meanwhile i've found out in SP-wiki^^ my code so far: if frame==1;setVar("acc",0.5);end; if key("a")==1;setVar("acc",0.6); elsif key("s")==1;setVar("acc",0.7); elsif key("d")==1;setVar("acc",0.8); elsif key("f")==1;setVar("acc",0.9); elsif key("g")==1;setVar("acc",1); elsif key("r")==1;setVar("acc",0.4); elsif key("e")==1;setVar("acc",0.5);end; getVar("acc")-0.5 with a,s,d,f,g for gears, e for empty and r for reverse
    • 1 / 1