[SOLVED] Can't get recieve fields working

IKRadulov
Member
 
Posts: 19
Joined: Thu Nov 10, 2016 11:02

[SOLVED] Can't get recieve fields working

by IKRadulov » Fri Nov 11, 2016 15:30

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
Last edited by IKRadulov on Mon Nov 14, 2016 01:29, edited 1 time in total.
 

cheapie
Member
 
Posts: 304
Joined: Mon May 14, 2012 00:59
GitHub: cheapie
IRC: cheapie
In-game: cheapie

Re: Can't get recieve fields working

by cheapie » Sat Nov 12, 2016 21:16

IKRadulov wrote:if forname ~= "beds:sleep_time" then


Change forname to formname and try again.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Can't get recieve fields working

by rubenwardy » Sun Nov 13, 2016 00:25

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
 

IKRadulov
Member
 
Posts: 19
Joined: Thu Nov 10, 2016 11:02

Re: Can't get recieve fields working

by IKRadulov » Sun Nov 13, 2016 17:45

Thank you . I haven't noticed the typo error . And thank you rubenwardy . Althought the fields checking works ok .
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 7 guests

cron