Pressing spacebar in formspecs bug
If there's a formspec with an button_exit
and a click on that button is supposed to trigger minetest.show_formspec
and one presses spacebar instead of clicking on that very button
then the button gets visually activated and runs on_receive_fields
but minetest.show_formspec fails to show a formspec although no errors or exceptions raise.
AN "EXAMPLED" EXPLANATION:
First of all - some code:
Now onto explanation:
At 04:44:26 server issues "/kill" chat command and gets killed: ACTION[ServerThread]: server was instantly killed.
Minetest running on death function, which actually looks like this:
*Note the line with ghosts[pll]=1 - we'll return to it later.
A formspec with the button 'Respawn' appears and server presses spacebar in order to not to have to click that button with LMB.
As a result, server respawns: ACTION[ServerThread]: server respawns at (0,0,0).
The function, registered with minetest.register_on_respawnplayer(function(player)) gets executed. I've checked that with various debug messages.
That function is supposed to show a formspec to a player with the announce he's a ghost and bla-bla-bla:
Remember that first 'note'?
Here, ghosts[pll] has a flag that a player is dead and ghosts4[pll] a flag that there's no need to repeat the whole announce - player wants only buttons.
Now note the line with the minetest.show_formspec(pll,"ghosts:unlocked",formspec), as the desired formspec won't show up!
BUT!!!
At 04:44:55 server kills himself with the "/kill" command once again: ACTION[ServerThread]: server was instantly killed.
A formspec with the button 'Respawn' appears but this time server CLICKS the button with LMB.
As a result, server respawns and a formspec, that should've been shown, gets shown.
One can repeat it with ANY formspecs which apply to the following conditions:
- have a button, registered as "button_exit";
- call another formspec within on_receive_fields (either that of node or one registered with the minetest.register_on_player_receive_fields() function call).
For example:
The formspec:
The on_receive_fields function extracts:
Again, pressing spacebar in the first formspec will guarantee with the precision of 99% that minetest.show_formspec() won't show anything
and a click on that button is supposed to trigger minetest.show_formspec
and one presses spacebar instead of clicking on that very button
then the button gets visually activated and runs on_receive_fields
but minetest.show_formspec fails to show a formspec although no errors or exceptions raise.
AN "EXAMPLED" EXPLANATION:
First of all - some 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
04:44:26: ACTION[ServerThread]: server was instantly killed.
running on death function
04:44:27: ACTION[ServerThread]: Moving server to static spawnpoint at (0,0,0)
04:44:27: ACTION[ServerThread]: server respawns at (0,0,0)
04:44:47: ACTION[ServerThread]: CHAT: <server> I've pressed a spacebar
04:44:55: ACTION[ServerThread]: server was instantly killed.
running on death function
04:44:57: ACTION[ServerThread]: Moving server to static spawnpoint at (0,0,0)
04:44:57: ACTION[ServerThread]: server respawns at (0,0,0)
{
g_reinc = "Reincarnation",
yng = "You're still dead!\
As a ghost you can do something you previously can't.\
Flying is just an example.\
On the other hand now you must do some semi-difficult\
tasks to restore your previous state as it was.\
Actually, you can press the 'Reincarnation' button,\
but are you ready to lose everything you have?\
If you are NOT concerned about it then bravely\
reincarnate. Otherwise you should undergo the ritual\
of rebirth.\
But how are you supposed to warn others about your death?",
quit = "true"
}
ghosts:unlocked
04:45:29: ACTION[ServerThread]: CHAT: <server> Now I've clicked it with LMB
Now onto explanation:
At 04:44:26 server issues "/kill" chat command and gets killed: ACTION[ServerThread]: server was instantly killed.
Minetest running on death function, which actually looks like this:
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_on_dieplayer(function(player)
if player then
local pll=player:get_player_name()
if not deaths_count[pll] then deaths_count[pll] = 0 end
if isghost[pll] then
deaths_count[pll] = deaths_count[pll] + 1
end
local pos = player:getpos()
bdeathpos[pll]=pos
ghosts[pll]=1
end
end)
*Note the line with ghosts[pll]=1 - we'll return to it later.
A formspec with the button 'Respawn' appears and server presses spacebar in order to not to have to click that button with LMB.
As a result, server respawns: ACTION[ServerThread]: server respawns at (0,0,0).
The function, registered with minetest.register_on_respawnplayer(function(player)) gets executed. I've checked that with various debug messages.
That function is supposed to show a formspec to a player with the announce he's a ghost and bla-bla-bla:
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_on_respawnplayer(function(player)
local pll=player:get_player_name()
if (ghosts[pll]) then
if rus == 1 then -- russian
localized_announce = announce_rus
localized_close = close_rus
localized_reinc = reinc_rus
localized_welcome = welcome_rus
localized_remin = remin_rus
else -- english
localized_announce = announce_not_rus
localized_close = close_not_rus
localized_reinc = reinc_not_rus
localized_welcome =welcome_not_rus
localized_remin = remin_not_rus
end
local formspec = ''
if (not ghosts4[pll]) then
formspec = "size[9,9]"..
"bgcolor[#bbbbbb;false]"..
"listcolors[#777777;#cccccc;#333333;#555555;#dddddd]"..
"label[0.25,0.2;" .. localized_welcome .."]"..
"textarea[0.25,0.5;9,7.8;yng; ;"..localized_announce.."]"..
"checkbox[0.25,7.2;g_rem;" .. localized_remin .. ";false]"..
"button_exit[1.5,8.0;2.5,1;g_close;" .. localized_close .."]"..
"button_exit[5,8.0;2.5,1;g_reinc;" .. localized_reinc .."]"
else
formspec = "size[9,2]"..
"bgcolor[#bbbbbb;false]"..
"listcolors[#777777;#cccccc;#333333;#555555;#dddddd]"..
"label[0.25,0.2;" .. localized_welcome .."]"..
"button_exit[1.5,1.0;2.5,1;g_close;" .. localized_close .."]"..
"button_exit[5,1;2.5,1;g_reinc;" .. localized_reinc .."]"
end
-- if a player is NOT a ghost
if pll and formspec and not isghost[pll] then
minetest.show_formspec(pll,"ghosts:unlocked",formspec)
end
else
end
return true
end)
Remember that first 'note'?
Here, ghosts[pll] has a flag that a player is dead and ghosts4[pll] a flag that there's no need to repeat the whole announce - player wants only buttons.
Now note the line with the minetest.show_formspec(pll,"ghosts:unlocked",formspec), as the desired formspec won't show up!
BUT!!!
At 04:44:55 server kills himself with the "/kill" command once again: ACTION[ServerThread]: server was instantly killed.
A formspec with the button 'Respawn' appears but this time server CLICKS the button with LMB.
As a result, server respawns and a formspec, that should've been shown, gets shown.
One can repeat it with ANY formspecs which apply to the following conditions:
- have a button, registered as "button_exit";
- call another formspec within on_receive_fields (either that of node or one registered with the minetest.register_on_player_receive_fields() function call).
For example:
The formspec:
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
"size[9,8.2]" ..
"bgcolor[#bbbbbb;false]"..
"listcolors[#777777;#cccccc;#333333;#555555;#dddddd]"..
"image_button[9.0,-0.3;0.80,1.7;b_bg2.png;just_bg;Z;true;false]"..
"image_button[9.2,-0.2;0.5,0.5;b_bg.png;sort_horz;=;true;true]"..
"image_button[9.2,0.3;0.5,0.5;b_bg.png;sort_vert;||;true;true]"..
"image_button[9.2,0.8;0.5,0.5;b_bg.png;sort_norm;Z;true;true]"..
"label[1.2,1;".. txt .."]"..
"label[1.2,1.5;".. txt2 .."]"..
"label[1.2,2;".. txt3 .."]"..
"list[context;gb_place;6,1;1,1;]"..
"label[7,1; +".. meta:get_string("stored") .."]"..
"button[5,2;3,1;g_chk;"..txt5.."]"..
"button_exit[5,3;3,1;g_rei;".. txt4 .."]"..
"list[current_player;helm;0,0;1,1;]"..
"list[current_player;torso;0,1;1,1;]"..
"list[current_player;pants;0,2;1,1;]"..
"list[current_player;boots;0,3;1,1;]"..
"list[current_player;main;0,4.2;9,3;9]"..
"list[current_player;main;0,7.4;9,1;]"
The on_receive_fields function extracts:
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_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
if fields.g_chk then
..................................... - skipped
end
if fields.g_rei then
local player=sender
if player and player:is_player() then
local pll = player:get_player_name()
if not isghost[pll] then
minetest.show_formspec(pll, pll..'_is_not_a_ghost', 'size[5,1]bgcolor[#bbbbbb;false]label[1.3,0;You\'re not a ghost!]button_exit[1.5,0.5;2,1;g_proceed;Proceed]')
return
end
..................................... - skipped
Again, pressing spacebar in the first formspec will guarantee with the precision of 99% that minetest.show_formspec() won't show anything