Page 1 of 1

When would moho:Skeleton() be an or nil?

Posted: Wed Feb 07, 2007 4:43 pm
by heyvern
Actually in one of my functions it keeps telling me that I'm trying to:

Code: Select all

attempt to index global 'moho' (a nil value)
This happens whenever I try to call "moho:anything"

I have a function that is called at the end of the "OnOk" function. I have no clue. Is there a different way to access that? When would "moho" be nil?

Should it run in the "Run" function? I've got so much going on that I'm losing track of when things happen. Doesn't ":Run" occur at the moment the menu script is called? And "OnOk" run after the okay button is hit?

It actually works if the pasting function runs inside the :Run function of the script. However I think there are some values that haven't been set yet as I get errors on different tables being "nil" when they most definitely shouldn't be nil at that point.

-vern

Posted: Wed Feb 07, 2007 7:07 pm
by Rasheed
You always need to pass moho as a parameter to a function that uses moho, otherwise it becomes nil (undefined).

Code: Select all

function SomeFunction(moho)
    local x, y = 1, -1
    local myVal = AnotherFunction(moho, x, y)
    if myVal == nil then
        print("something is not right")
        return
    end
--  ...
end

function AnotherFunction(moho, a, b)
    if moho:Skeleton() == nil then return
    return math.sqrt(a * a + b * b)
end