No goddamn clue why it's like that.
error:
sound.lua:16: attempt to compare number with nil
Traceback
[love "callbacks.lua"]:228: in function 'handler'
sound.lua:16: in function 'update'
[love "callbacks.lua"]:162: in function <[love "callbacks.lua"]:144>
[C]: in function 'xpcall'
sound.lua:
Code: Select all
function love.load()
coolSound = 0
soundCool = 0
local playingSound = 0
local jamAudio = 0
local jamLoopable = 0
end
function love.update()
if coolSound == 0 then
soundCool = 0
end
if soundCool > 150 then
coolSound = 0
end
end
--"sound" is a string that's defined when the programmer runs jamSound.
--It's the path to the sound they want to play.
--I.E. jamSound("sounds/fuckyou.wav")
function jamSound(sound, cd) --cd stands for cooldown. Toggles if the cooldown stuff is ran.
if cd == 1 then --the cooldown thing is for times when jamSound() is run multiple times, while the sound is meant to play once.
coolSound = 1 -- soundCool can't be set to 0 anymore
soundCool = soundCool + 1 --soundCool goes up every time the code is ran
if soundCool == 1 then --on the first frame soundCool goes up,
jamAudio = love.audio.newSource(sound, "static") --decides what audio to play
love.audio.play(jamAudio) --actually plays the audio
end
elseif (cd == 0) or (cd == nil) then
jamAudio = love.audio.newSource(sound, "static") --decides what audio to play
love.audio.play(jamAudio) --actually plays the audio
end
end
Code: Select all
function love.load()
defineVar()
require("sound") --adds jamSound(sound) and jamMusic(music, loop?)
sonicSprite = love.graphics.newImage("sonic.png")
print("Loaded Sonic sprite ", sonicSprite:getWidth(), "x", sonicSprite:getHeight(), "px")
jamMusic("music/test.WAV")
end
function love.update(dt)
if love.keyboard.isDown("left") then --moving left?
if grndSpeed > 0 then --if moving right still,
grndSpeed = grndSpeed - decelSpeed --decelerate
jamSound("sounds/skid.WAV", 1)
if grndSpeed <= 0 then
grndSpeed = -0.5 --deceleration quirk
end
elseif grndSpeed > -topSpeed then --if actually moving left,
grndSpeed = grndSpeed - accelSpeed --accelerate
if grndSpeed <= -topSpeed then
grndSpeed = -topSpeed --stay at the top speed
end
end
end
if love.keyboard.isDown("right") then --moving right?
if grndSpeed < 0 then --still moving left?
grndSpeed = grndSpeed + decelSpeed --decelerate
jamSound("sounds/skid.WAV", 1)
if grndSpeed >= 0 then
grndSpeed = 0.5 --deceleration quirk
end
elseif grndSpeed < topSpeed then --if finally moving right,
grndSpeed = grndSpeed + accelSpeed --accelerate
if grndSpeed >= topSpeed then
grndSpeed = topSpeed --stay at top speed
end
end
end
end