Page 1 of 1

Help with formspecs?

PostPosted: Sun Jun 05, 2016 20:21
by Tmanyo
I am new to modding so go easy on me. Is there a way for a player to input a string of words in the field box and index key-words in the string they submitted to supply the player an answer through a list of possible answers?

Re: Help with formspecs?

PostPosted: Mon Jun 06, 2016 17:22
by Krock
First of all, there are basically two questions:
1) How do I use text input fields?
2) Searching a text element in a list

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
Formspec element for your text input:
field[x pos,y pos;width,height;field_name;label text;]

Getting the formspec callback (when pressing a button)
minetest.register_on_player_receive_fields(function(sender, formname, fields)
   if formname ~= "formspec_name" then
      return
   end
   if not fields["field_name"] then
      return
   end
   
   -- String lookup code
end)


And now the text value search part:
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
local mytable = {
   "stuff1 things",
   "foobar attack",
   "string operation",
   "iamstupid.com"
}
-- Looking through the whole table
for i,v in ipairs(mytable) do
   if string.match(string.lower(v), "text to search") then
      -- Found something!
   end
end

Re: Help with formspecs?

PostPosted: Mon Jun 06, 2016 21:37
by Tmanyo
Thank you, Krock. You answered my question.