Created
May 26, 2018 00:57
-
-
Save entuland/4390231d607221b96eed6c1a0eb5e7ca to your computer and use it in GitHub Desktop.
Minetest formspec list -> field interaction test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interact = {} | |
interact.chosen = {} | |
function interact.command(playername, param) | |
minetest.show_formspec(playername, "myform", interact.getform(playername)) | |
end | |
function interact.receive(player, formname, fields) | |
local playername = player:get_player_name() | |
if fields.list then | |
local action, index = fields.list:match("(.+):(.+)") | |
index = tonumber(index) | |
interact.chosen[playername] = ({"one", "two", "three"})[index] | |
minetest.show_formspec(playername, formname, interact.getform(playername)) | |
end | |
end | |
function interact.getform(playername) | |
local chosen = interact.chosen[playername] or "none" | |
local form = [[ | |
size[5,5] | |
field[1,1;3,1;chosen;Chosen;]] .. chosen .. [[] | |
textlist[0,2;3,3;list;one,two,three] | |
]] | |
return form | |
end | |
minetest.register_on_player_receive_fields(interact.receive) | |
minetest.register_chatcommand("inter", {func = interact.command}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment