I’m getting errors that I don’t understand, can someone shed some light on the subject.
attempt to index field ‘velocity’ (a nil value)
attempt to call global ‘play_animation’ (a nil value)
attempt to index global ‘pos’ (a nil value)
I’m getting errors that I don’t understand, can someone shed some light on the subject.
attempt to index field ‘velocity’ (a nil value)
attempt to call global ‘play_animation’ (a nil value)
attempt to index global ‘pos’ (a nil value)
local foo = nil
print(foo.velocity) -- attempt to index field ‘velocity’ (a nil value)
print(foo.pos) -- attempt to index global ‘pos’ (a nil value)
play_animation() -- attempt to call global ‘play_animation’ (a nil value)
There is no function named “play_animation”
Could you post the script file? Even though @britzl has provided the reasons why these messages are posted, with your code we can find out explicitly what you wrote wrong.
I found the problem I was using the syntax for play_animation and “pos” incorrectly that made them appear as some type of variable.
However I cant seem to find the syntax that locates the current x and y position can I get some help, and the velocity problem is annoying me, I can’t seem to find a solution, the problem is involved with three game objects, two move according to to one.
function init(self)
self. x = go.get_position(".", "position.x")
self.y = go.get_position(".", "position.y")
self.z = go.get_position(".", "position.z")
end
function on_message(self, message_id, message, sender)
if (message.id == hash("trigger_response")) then
msg.post("points#points", "pieup")
go.set_position(vmath.vector3(0, 700, 0))
end
if (message.id == hash("menu")) then
go.set_position(vmath.vector3(self.x , self.y, self.z))
end
end
function init(self)
self.speech = 0
-- 0 = none; 1 = apple; 2 = cream; 3 = blue; 4 = choc; 5 = moldy; 6 = lemon; 7 = door
self.pos = 1
-- 1 = left side; 2 = right side
go.set_position(go.get_position("player"))
end
function update(self, dt)
if (go.get_position("player", "position.x") >= 0) then
self.pos = 2
end
if (go.get_position("player", "position.x") < 0) then
self.pos = 1
end
if (self.speech == 0) then
go.set_position(vmath.vector3(0, 21, 0))
end
if (self.speech == 1) then
if (self.pos == 1) then
msg.post(".", "play_animation", {id = hash("applel")})
self.speech = 0
else
msg.post(".", "play_animation", {id = hash("appler")})
self.speech = 0
end
end
if (self.speech == 2) then
if (self.pos == 1) then
msg.post(".", "play_animation", {id = hash("creaml")})
self.speech = 0
else
msg.post(".", "play_animation", {id = hash("creamr")})
self.speech = 0
end
end
if (self.speech == 3) then
if (self.pos == 1) then
msg.post(".", "play_animation", {id = hash("bluel")})
self.speech = 0
else
msg.post(".", "play_animation", {id = hash("bluer")})
self.speech = 0
end
end
if (self.speech == 4) then
if (self.pos == 1) then
msg.post(".", "play_animation", {id = hash("chocol")})
self.speech = 0
else
msg.post(".", "play_animation", {id = hash("chocor")})
self.speech = 0
end
end
if (self.speech == 5) then
if (self.pos == 1) then
msg.post(".", "play_animation", {id = hash("moldyl")})
self.speech = 0
else
msg.post(".", "play_animation", {id = hash("moldyr")})
self.speech = 0
end
end
if (self.speech == 6) then
if (self.pos == 1) then
msg.post(".", "play_animation", {id = hash("lemonl")})
self.speech = 0
else
msg.post(".", "play_animation", {id = hash("lemonr")})
self.speech = 0
end
end
if (self.speech == 7) then
msg.post(".", "play_animation", {id = hash("cantleave")})
self.speech = 0
end
end
function on_message(self, message_id, message, sender)
if (message.id == hash("door")) then
self.speech = 7
end
if (message.id == hash("apple")) then
self.speech = 1
end
if (message.id == hash("cream")) then
self.speech = 2
end
if (message.id == hash("blue")) then
self.speech = 3
end
if (message.id == hash("choco")) then
self.speech = 4
end
if (message.id == hash("moldy")) then
self.speech = 5
end
if (message.id == hash("lemon")) then
self.speech = 6
end
end
Player Script :
function init(self)
msg.post(".", "release_input_focus")
self.velocity.x = 0
self.velocity.y = 0
self.wl = 0
self.scream = 0
go.set_position(vmath.vector3(560, 970, 0))
-- 1 = win; 2 = lose
end
function update(self, dt)
repeat
if (self.velocity.x == left) then
local z = go.get_position(".", "position.z")
local y = go.get_position(".", "position.y")
local x = go.get_position(".", "position.x") - 4
go.set_position(vmath.vector3(x, y, z))
end
if (self.velocity.x == right) then
local z = go.get_position(".", "position.z")
local y = go.get_position(".", "position.y")
local x = go.get_position(".", "position.x") + 4
go.set_position(vmath.vector3(x, y, z))
end
if (self.velocity.x == up) then
local z = go.get_position(".", "position.z")
local y = go.get_position(".", "position.y") + 4
local x = go.get_position(".", "position.x")
go.set_position(vmath.vector3(x, y, z))
end
if (self.velocity.y == down) then
local z = go.get_position(".", "position.z")
local y = go.get_position(".", "position.y") - 4
local x = go.get_position(".", "position.x")
go.set_position(vmath.vector3(x, y, z))
end
until (self.wl > 0)
if (self.velocity.x == left) then
msg.post(".", "play_animation", {id = hash("left")})
end
if (self.velocity.x == right) then
msg.post(".", "play_animation", {id = hash("right")})
end
if (self.velocity.y == down) then
msg.post(".", "play_animation", {id = hash("down")})
end
if (self.velocity.y == up) then
msg.post(".", "play_animation", {id = hash("up")})
end
if (self.velocity.y ~= up and self.velocity.y ~= down and self.velocity.x ~= right and self.velocity.x ~= left) then
if (self.scream == 0) then
msg.post(".", "play_animation", {id = hash("stand")})
end
end
end
function on_message(self, message_id, message, sender)
if (message.id == hash("heartdown")) then
msg.post(".", "release_input_focus")
self.scream = 1
self.velocity.x = 0
self.velocity.y = 0
msg.post(".", "play_animation", {id = hash("scream")})
msg.post(".", "play_animation", {id = hash("cooldown")})
msg.post(".", "aquire_input_focus")
self.scream = 0
end
if (message.id == hash("pause")) then
msg.post(".", "release_input_focus")
msg.post(".", "play_animation", {id = hash("stand")})
end
if (message.id == hash("pplay")) then
msg.post(".", "aquire_input_focus")
end
if (message.id == hash("play")) then
msg.post(".", "aquire_input_focus")
end
if (message.id == hash("win")) then
msg.post(".", "release_input_focus")
go.set_position(vmath.vector3(560, 970, 0))
end
if (message.id == hash("lose")) then
msg.post(".", "release_input_focus")
go.set_position(vmath.vector3(560, 970, 0))
end
end
function on_input(self, action_id, action)
if (action_id == hash("left") and action.pressed) then
if (self.velocity.x ~= right) then
repeat
self.velocity.x = left
until (action.released or self.velocity.x == right)
self.velocity.x = 0
end
end
if (action_id == hash("right") and action.pressed) then
repeat
self.velocity.x = right
until (action.released)
self.velocity.x = 0
end
if (action_id == hash("up") and action.pressed) then
if (self.velocity.y ~= down) then
repeat
self.velocity.y = up
until (action.released or self.velocity.y == down)
self.velocity.y = 0
end
end
if (action_id == hash("down") and action.pressed) then
repeat
self.velocity.y = down
until (action.released)
self.velocity.y = 0
end
end