Hello,
I am realy confused.
First i though i had a solution found here
however i wanted to have multple parameter in my own function
So just to be clear, when you do
self.value = value
at the init part of the script it will be created for the whole script.
just like a go.property is doing,
But with both i got the , cant get the value.
now i do think its about how i work with the parameters.
Goal.
I have a function called engine to do the engine sound.
On movement the function will be called with on
and on release it will be called with off
depending on the esound boolean it starts or stop playing.
however. i dont seems to get it working correctly.
Any tips?
go.property ("next",hash("stone"))
go.property ("hight", 500)
go.property("canbuild", true)
go.property("esound", false)
function engine (a, self)
--print(self.esound)
print(a)
if a == "on" and self.esound == false then
sound.plays("/sounds#engine",{gain = 0.4})
self.esound = true
print("play")
end
if a == "off" and self.esound == true then
sound.stop("/sounds#egine")
self.esound = false
print("stop")
end
end
function on_input(self, action_id, action)
--timer.delay(0.5, false, function()
--mouse movement
--[[if message_id == nil then
self.speed = 200
local current_pos = go.get_position()
local target_pos = vmath.vector3(action.x, self.hight, 0) -- <5>
local distance = vmath.length(target_pos - current_pos) -- <6>
local duration = distance / self.speed -- <7>
go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, target_pos, go.EASING_LINEAR, duration, 0)--end)
end
--]]
-- keybord movement
if action_id == hash("up") then
self.pos.y = 5
msg.post("#alien", "play_animation", {id = hash("stil")})
particlefx.play("#movingup")
engine("on")
end
if action_id == hash("left") then
self.pos.x = -5
msg.post("#alien", "play_animation", {id = hash("left")})
particlefx.play("#movingleft")
engine("on")
end
if action_id == hash("right") then
self.pos.x = 5
msg.post("#alien", "play_animation", {id = hash("right")})
particlefx.play("#movingright")
engine("on")
end
if action_id == hash("down") then
self.pos.y = -5
msg.post("#alien", "play_animation", {id = hash("stil")})
particlefx.play("#movingdown")
engine("on")
end
if action.released then
self.pos = vmath.vector3(0, 0, 0)
local animation = go.get("#alien", "animation")
particlefx.stop("#movingleft")
particlefx.stop("#movingup")
particlefx.stop("#movingdown")
particlefx.stop("#movingright")
engine("off")
if animation == hash("left") then msg.post("#alien", "play_animation", {id = hash("leftstil")}) end
if animation == hash("right") then msg.post("#alien", "play_animation", {id = hash("rightstil")}) end
end