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)