Topic: dofile error

I am trying to call a function from a lua script located dofile("other/Motion.lua")

When I try to run the Move() function (located in the Motion.lua file) I get an error:

[string "dofile<"other/Motion.lua">...]:17 attempt to call global 'Move' <a nil value>

What could be causing this? all of the arguments are in the Motion.lua file.

The function in the Motion.lua file:

function Move(move_object,move_direction,move_btn,move_animation,idle_animation)
    if isKeyPressed(move_btn) then
        changeAnimation(move_object,move_animation)
        translate(move_object,move_direction,"local")
        playSound(move_sound)
        setAnimationSpeed(move_object, move_animation_speed)
        
    end    
    
    if onKeyDown(move_btn) then
        playSound(move_sound)
    end
    
    if onKeyUp(move_btn) then
        changeAnimation(move_object,idle_animation)
        setAnimationSpeed(move_object, idle_animation_speed)
        stopSound(move_sound)
    end
    
end

How I use it in the main file:

box = getObject("Box") -- in the main scene
function onSceneUpdate()
Move(box,move_forward,move_btn_U)
    Move(box,move_backward,move_btn_D)
    Move(box,move_left,move_btn_L)
    Move(box,move_right,move_btn_R)
    
    --Jump Box
    Jump(box,jump_up,jump_btn)
    
    --Spin Box
    Spin(box,spin_left,spin_btn_L)
    Spin(box,spin_right,spin_btn_R)
end

Last edited by Tutorial Doctor (2014-04-04 22:45:13)

Re: dofile error

Maybe it's because your Move() function expects 5 arguments and only 3 are passed.

Last edited by com3D (2014-04-05 06:05:33)

Re: dofile error

It's not that. I changed that already

Re: dofile error

Where is located the script calling dofile("other/Motion.lua") ?

ex 1 :
/scripts/main.lua -> call dofile("other/Motion.lua")
/scripts/other/Motion.lua

ex 2 :
/scripts/something/main.lua -> call dofile("../other/Motion.lua")
/scripts/other/Motion.lua

Re: dofile error

Yes, it is like Example 1.

Re: dofile error

This might be a bug or something. This happened with another lua file, but when I moved it to the same folder as the main lua file, it worked.