Page 1 of 1

[SOLVED] Can't get recieve fields working

PostPosted: Fri Nov 11, 2016 15:30
by IKRadulov
Hello . I have this :
minetest.show_formspec(name,"beds:sleep_time","size[4,3]" ..
"label[0,0;Sleep time:]" ..
"button_exit[0,1;1,1;name;1]" ..
"button_exit[1,1;1,1;name;2]" ..
"button_exit[2,1;1,1;name;3]" ..
"button_exit[3,1;1,1;name;4]" ..
"button_exit[0,2;1,1;name;5]" ..
"button_exit[1,2;1,1;name;6]" ..
"button_exit[2,2;1,1;name;7]" ..
"button_exit[3,2;1,1;name;8]" )
end

And
minetest.register_on_player_receive_fields(function(player, formname, fields)
if forname ~= "beds:sleep_time" then
minetest.chat_send_player(player:get_player_name(), "Formname: " .. formname)
return false
end

day_time = minetest.get_timeofday() * 24000

if fields.name == "1" then
day_time = day_time+1000
elseif fields.name == "2" then
day_time = day_time+2000
elseif fields.name == "3" then
day_time = day_time+3000
elseif fields.name == "4" then
day_time = day_time+4000
elseif fields.name == "5" then
day_time = day_time+5000
elseif fields.name == "6" then
day_time = day_time+6000
elseif fields.name == "7" then
day_time = day_time+7000
elseif fields.name == "8" then
day_time = day_time+8000
else
minetest.chat_send_player(player:get_player_name(),"Guess I am not going to sleep now ..")
beds.kick_players()
return true
end

day_time = day_time / 24000

if day_time > 1.0 then
day_time = 0.2
end

-- skip the night and let all players stand up
if check_in_beds() then
minetest.after(2, function()
if not is_sp then
update_formspecs(is_night_skip_enabled())
end
if is_night_skip_enabled() then
beds.set_time(day_time)
beds.kick_players()
end
end)
end

return true

end)

The problem is with the check if the formname is equal to the defined one . When the check is run it prints out the correct name declared but this shoud be printed when its not equal

Re: Can't get recieve fields working

PostPosted: Sat Nov 12, 2016 21:16
by cheapie
IKRadulov wrote:if forname ~= "beds:sleep_time" then


Change forname to formname and try again.

Re: Can't get recieve fields working

PostPosted: Sun Nov 13, 2016 00:25
by rubenwardy
Also, buttons don't submit their label - they submit a boolean

so it should be:

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
button_exit[x,y;w,h;name_foo;Label text]
button_exit[x,y;w,h;name_bar;Label text]


then

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
if fields.name_foo then

elseif fields.name_bar then

end


Also, you should use local variables: http://rubenwardy.com/minetest_modding_ ... and-global

Re: Can't get recieve fields working

PostPosted: Sun Nov 13, 2016 17:45
by IKRadulov
Thank you . I haven't noticed the typo error . And thank you rubenwardy . Althought the fields checking works ok .