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

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

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

Post 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
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post 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
Post Reply