How to fix?

SapphireTheGreat

Your average coder.
// Super sonic!
addHook("PlayerThink", function(player)
freeslot("sfx_hmssuper")
if player.powers[pw_super] and player.mo and player.mo.skin == "h.r"
S_StartSound(player.mo, sfx_hmssuper)
if not player.powers[pw_super] and player.mo and player.mo.skin == "h.r"
S_StopSound(player.mo, sfx_hmssuper)
end
end
end)
It should be working, but it's not it's giving the error message "This function cannot be called from within a hook or coroutine!"
 
quite a simple fix, actually! you're gonna want to put the freeslot("sfx_hmssuper") outside of the hook, or above the addHook line, since you can't freeslot anything inside a hook (which explains the error message)!
 
quite a simple fix, actually! you're gonna want to put the freeslot("sfx_hmssuper") outside of the hook, or above the addHook line, since you can't freeslot anything inside a hook (which explains the error message)!
but how it would look like? i don't know what to do
 
but how it would look like? i don't know what to do
like this:

Lua:
freeslot("sfx_hmssuper")

// Super sonic!
addHook("PlayerThink", function(player)
    if player.powers[pw_super] and player.mo and player.mo.skin == "h.r"
        S_StartSound(player.mo, sfx_hmssuper)
    elseif not (player.powers[pw_super] and player.mo and player.mo.skin == "h.r")
        S_StopSound(player.mo, sfx_hmssuper)
    end
end)

though it's not part of what i explained earlier, i also added an elseif to the code, because without it you wouldn't be able to stop the music from playing, because the if statement that cancels the music is inside the if statement that starts the music which...doesn't make a lot of sense!
 
it gave bad argument #2 to 'S_StartSound' number expected, got nil"
The sound name is too big. Sounds can only be up to 6 characters excluding the DS/sfx_ part. So you would have to rename the DSHMSSUPER to DSHMSSUP and sfx_hmssuper to sfx_hmssup
 

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top