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