12Me22 wrote:My partner 12Me21 and I don't know a lot about this type of coding. Can you guide us with more details?
What syntax error, what is the proper indentation?
Thanks,
PilzAdam wrote:12Me21 wrote:So I would do
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
on_metadata_inventory_put = function(pos, listname, index, stack, player),
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25})
end
(I've never done anything with formspecs, so this is probably completely wrong)
1.) There is a Lua syntax error
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).
For proper indentation read a tutorial about coding (the language doesnt matter).
There are several syntax errors, here is the fixed code.
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
on_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25})
end
end,
To play the sound at a position, just specify the pos field in the sound parameter table, like:
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
on_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25, pos=pos})
end
end,
Note that only mono channel sound files can be played at a position. Also only ogg files are supported.
To get the name of a ItemStack, use get_name():
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
on_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack:get_name() == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25, pos=pos})
end
end,