# ProblemCode works as an upper level function, but not when called.

#### dmurley

##### New member
I have a piece of code to establish a constant vertical velocity on the moon of 1 m/s which works just fine when invoked directly, but not when called. When called, the Delta Glider NT barely moves at all and settles back to the ground very quickly. I don't understand what is going on here. Any help would be appreciated.

Also, I am using 1.622 as the gravitational acceleration of the moon. I actually get better results using 1.624. What is the proper value to use?

Code:
-- VelOne
--
-- Description: The purpose of this function is to establish
-- a constant vertical velocity of about 1 m/s on the moon.
--
-- Inputs:
--   dAcc - desired acceleration in g's
--
--   Assumptions:
--   1) A handle (hGLNT) to the interface of a vessel
--      is established before this routine is invoked.

function VelOne(dAcc)

term.out ('Enter VelOne')
pbA=1.622
sA = (9.8*dAcc)-pbA
tA = 1/sA
curMass = hGLNT:get_mass()
gF=curMass*pbA
aF = curMass*sA
tF=gF+aF
eng0F=tF*.6026
eng0L=eng0F/110000
eng0HF=gF*.6026
eng0HL=eng0HF/110000
hGLNT:set_thrustergrouplevel(THGROUP.HOVER,eng0L)
proc.wait_simdt(tA)
hGLNT:set_thrustergrouplevel(THGROUP.HOVER,eng0HL)
proc.wait_simdt(tA)
term.out ('Exit VelOne')
end

#### jedidia

##### shoemaker without legs
I'm not sure I follow... Invoking a function and calling it are the same thing. Maybe you could post the calling code as well?

#### kuddel

##### Donator
Donator
I'm not sure what you mean by "called" vs. "invoked"...

If it is something about "automatically run at scenario start" vs. "manually run later on", here's my guess:
It could be that the friction of the landing gear (wheels) make a difference, as they might not have gotten fully integrated into the (simulation-)state at scenario start.
When running the function manually (later that is) the friction might be fully integrated...

Note: this is only a guess, as I think I read something like this in another thread...

#### Linguofreak

##### Well-known member
I think what he means is that the function works when run interactively by the user from the Lua console (I haven't run Orbiter in a while but I seem to recall there being a built-in MFD that functioned as a Lua console), but not when called programmatically.

#### jedidia

##### shoemaker without legs
In that case, logging the passed argument would be a good first thing to try.