orwell wrote:ulla wrote:HI all
I need to assign functions to my formspec
the function minetest.play_sound
track_1,2,3 ........... to 1,2,3 buttons, ...............
and minetest.stop_sound for the STOP button
EXIT button works well, but only that :-P]]
For try the mod and help me you can download mod prewiev
Code: Select all
https://www.dropbox.com/sh/82mmlx3bulbdngo/AABSjkhq_mud_-yIAsmOCAlOa?dl=0
SEE first the README
To assign functions to buttons, you need to use minetest.register_on_player_receive_fields().
If a player clicks a button on the client, this event gets sent to server. Every button has an internal name, this will be its name in the 'fields' table. When that button was pressed, its 'fields' entry is (evaluates to) true.
Code: Select all
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname=="<your formname>" then
if fields.quit then
--escape was pressed
elseif fields.<name of first button> then
--the first button was pressed
elseif fields.<name of second button> then
--the second one was pressed
[...]
end
end
end)
Of course without the <>, just simple lua table indexing.
You can also read the contents of text fields here:
Code: Select all
local contents_of_text_field = fields.<name of text field>
TY for answer and sorry for my english is my first problem i need big time for understand english tutor/ial :-) and the guides for formspec are mutch inexplicative :-( (for me :-P) this is my code
Code: Select all
local function play_track(pos, track)
return minetest.sound_play("juke_track_"..tostring(track),
{pos = pos, gain = 1.0, loop = true, max_hear_distance = 72,})
end
local function stop_player(pos, node)
local pos_hash = minetest.hash_node_position(pos)
local music_handle = music_handles[pos_hash]
if music_handle then
minetest.sound_stop(music_handle)
music_handles[pos_hash] = nil
end
end
-- Show form when the /formspec command is used.
minetest.register_chatcommand("juke", {
func = function(name, param)
minetest.show_formspec(name, "jukebox:form",
"size[4.0,4.5]" ..
"background[-0,-0;4,4.5;juke_bag.png]"..
"label[0,0;CIAO!!!, " .. name .. "]" ..
"field[0.3,2.5;4,1;ded;" .. name .. ", DEDICA;]" ..
"button[1,0.3;2,1;stop;STOP!]"..
"button[0,1;1,1;track_1;1]"..
"button[1,1;1,1;track_2;2]"..
"button[2,1;1,1;track_3;3]"..
"button[3,1;1,1;track_4;4]"..
"button[0,3;1,1;track_5;5]"..
"button[1,3;1,1;track_6;6]"..
"button[2,3;1,1;track_7;7]"..
"button[3,3;1,1;track_8;8]"..
"button_exit[1,3.7;2,1;exit;EXIT]")
end
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname=="jukebox:form"
local stop_player = 0
local " .. name .. ", DEDICA = fields.ded
local juke_track = nil
if fields.stop then juke_track = 0 end
elseif fields.track_1 then juke_track_ = 1 end
elseif fields.track_2 then juke_track_ = 2 end
elseif fields.track_3 then juke_track = 3 end
elseif fields.track_4 then juke_track = 4 end
elseif fields.track_5 then juke_track = 5 end
elseif fields.track_6 then juke_track = 6 end
elseif fields.track_7 then juke_track = 7 end
elseif fields.track_8 then juke_track = 8 end
elseif fields.track_9 then juke_track = 9 end
elseif ded then func = function(name, param)
minetest.chat_send_all(field)
end
end
end
end
)
help pls ty in advance