[solved] minetest.sound_play sometimes returns -1

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

[solved] minetest.sound_play sometimes returns -1

by burli » Sun May 08, 2016 08:55

I try to play sounds if torches are placed. I add some code to sofars torches mod to the on_place function. But it doesn't work reliable. Sometimes I got a -1 as handle and no sound is played

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
       local hpos = minetest.hash_node_position(pointed_thing.above)
       local torch = torch_sounds[hpos]
       if not torch then
           torch = {}
          torch_sounds[hpos] = torch
          torch.handle = minetest.sound_play("torch_burning",
            {pos=pointed_thing.above, max_hear_distance=3, gain=0.5, loop=true})
       end


I also try to "ignite" the torches when the server starts, but this is even more worse. Most times minetest.sound_play() returns -1, but not always.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_lbm({
   name = "torches:ignite_torches",
   run_at_every_load = true,
   nodenames = {"default:torch", "default:torch_wall"},
   action = function(pos, node)
       local hpos = minetest.hash_node_position(pos)
       local torch = torch_sounds[hpos]
       if not torch then
           torch = {}
          torch_sounds[hpos] = torch
          torch.handle = minetest.sound_play("torch_burning",
            {pos=pos, max_hear_distance=3, gain=0.5, loop=true})
       end
        print(dump(node), dump(pos), dump(torch_sounds))
   end,
})


What's going on here? I have absolutly no clue
Last edited by burli on Sun May 08, 2016 09:40, edited 1 time in total.
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: minetest.sound_play sometimes returns -1

by burli » Sun May 08, 2016 09:39

Got it. Everything outside max_hear_distance will not be played. I missunderstood "max_hear_distance". I's the distance ON CREATION to the player
 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 6 guests

cron