Page 1 of 1

For loop

Posted: Mon Oct 02, 2023 2:46 am
by amini_opensim
Hi

I would like to compute a variable in a For loop at scriptcontroller. I have done the following code in a script controller by lua

function init( model,par,side)
alpha0 = 1
alpha = 1
phi = 0

for i = 1,10 do
beta = alpha*sin(phi)
alpha_dot = beta + 2 -- differentiate alpha
alpha = math.modf (alpha) -- Integral alpha
end
end

In above code, I am attempting to compute alpha inside a FOR loop. But an error is occurred :

attempt to call a number value (global 'alpha')

How can I fix it?

Thanks in advance

Re: For loop

Posted: Mon Oct 02, 2023 5:13 am
by tgeijten
Perhaps add "math." before sin?

Re: For loop

Posted: Mon Oct 02, 2023 5:18 am
by amini_opensim
Hi

I corrected it. But it still doesn't work. Actually, the alpha(i) which i=1 isn't recognized.

Best

Re: For loop

Posted: Fri Oct 06, 2023 2:29 am
by tgeijten
It appears "alpha" is a number and not a function, so you can't do alpha(i).