Hey thanks for the reply, i'm not really a coder so i don´t know what (#walkSound) does i just know that if i remove the # from it the sounds stop playing. About making the function before calling it, i did that, i forgot to put a "end" on the code above but on the real code it is there, so the playsteepsounds() function is outside the onSceneUpdate() function.
below is the full code
-----------------------------------------------------------------------------------
-- Maratis
-- Jules script test
-----------------------------------------------------------------------------------
-- get objects
Player = getObject("Player")
Head = getObject("Head")
dx = 0.0
dy = 0.0
-- walk var
walkSound = {} -- array
walkSound[1] = getObject("walk1")
walkSound[2] = getObject("walk2")
walkSound[3] = getObject("walk3")
soundLenght = 0.3
walkSpeed = 3.0
-- jump code
playMass = getMass(Player)
jumpSpeed = playMass * 50.0
Sound0 = getObject("JumpSound")
soundplay = 0
-- Run vars
runSpeed = 4.0
centerCursor()
mx = getAxis("MOUSE_X")
my = getAxis("MOUSE_Y")
-- scene update
function onSceneUpdate()
setGravity({0,0,-2})
coll = getNumCollisions(Player) -- for the jump code
-- rotate Player (X mouse)
rotate(Player, {0, 0, -1}, dx*100)
-- rotate Head (Y mouse)
rotate(Head, {-1, 0, 0}, dy*100, "local")
rotation = getRotation(Head)
if rotation[1] > 90 then
rotation[1] = 90
elseif rotation[1] < -90 then
rotation[1] = -90
end
setRotation(Head, rotation)
-- move
if isKeyPressed("W") then
addCentralForce(Player, {0, walkSpeed, 0}, "local")
playsteepsounds()
end
if isKeyPressed("S") then
addCentralForce(Player, {0, -walkSpeed, 0}, "local")
end
if isKeyPressed("A") then
addCentralForce(Player, {-3, 0, 0}, "local")
end
if isKeyPressed("D") then
addCentralForce(Player, {3, 0, 0}, "local")
end
-- run
if isKeyPressed("W") and isKeyPressed("LSHIFT") then
addCentralForce(Player, {0, runSpeed, 0}, "local")
end
-- jump
if isKeyPressed("SPACE") then
if (coll >= 1) then
playmysound()
addCentralForce(Player, {0, 0, jumpSpeed}, "local")
print ("I jumped!!")
else
stopmysound()
end
end
-- get mouse direction
dx = getAxis("MOUSE_X") - mx
dy = getAxis("MOUSE_Y") - my
-- center cursor
centerCursor()
mx = getAxis("MOUSE_X")
my = getAxis("MOUSE_Y")
end
function playmysound()
if soundplay == 0 then playSound(Sound0) end
soundplay = 1
end
function stopmysound()
soundplay = 0
end
function playsteepsounds()
characterSounds = math.random(#walkSound)
playSound(walkSound[characterSounds])
end
Also i got the array code idea from here http://forums.coronalabs.com/topic/3558
ncomplete/