FormSpec Gurus... help please

blert2112
Member
 
Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

FormSpec Gurus... help please

by blert2112 » Tue Nov 24, 2015 22:30

How to...
append an ItemStack's meta string onto an inventory tooltip?

edit: I should probably explain myself a bit better. I know how to do it, by using...
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
tooltip[<gui_element_name>;<tooltip_text>]

...in the formspec. What I would like to do is something like this example...
Given some node: "test:test". Now lets say I have an itemstack for said node and I set it's metadata to "fast". In an inventory it's tooltip will say "test", because that is it's name. I want it to say "test fast".
Do you think this is possible without having to edit existing inventory/chest mods?
 

User avatar
kaadmy
Member
 
Posts: 627
Joined: Thu Aug 27, 2015 23:07
GitHub: kaadmy
IRC: KaadmY
In-game: KaadmY kaadmy NeD

Re: FormSpec Gurus... help please

by kaadmy » Wed Nov 25, 2015 01:24

Inventory slot tooltips are not configurable, and you can only change ones that you manually supply, like the ones on buttons, fields, etc.
Never paint white stripes on roads near Zebra crossings.
 

blert2112
Member
 
Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

Re: FormSpec Gurus... help please

by blert2112 » Wed Nov 25, 2015 02:19

That is bad news. Looks like I am going to have to figure something else out.
 

User avatar
kaadmy
Member
 
Posts: 627
Joined: Thu Aug 27, 2015 23:07
GitHub: kaadmy
IRC: KaadmY
In-game: KaadmY kaadmy NeD

Re: FormSpec Gurus... help please

by kaadmy » Wed Nov 25, 2015 14:58

Try this: https://github.com/kaadmy/pixture/blob/ ... ec.lua#L80
You can't use it as an itemstack/inventory, so you can't take/put/move items in it, but you can use as an icon with an arbitrary tooltip.
Never paint white stripes on roads near Zebra crossings.
 

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

Re: FormSpec Gurus... help please

by tbillion » Wed Nov 25, 2015 20:29

well since my title is already here why make a new post and all that... lol .

i have a formspec with a box and a button the button is just supposed to see if the number in the box is 100 or not, if so set a variable to 0 if so set it to one, any Gurus have a good SIMPLE example?
 

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

Re: FormSpec Gurus... help please

by rubenwardy » Thu Nov 26, 2015 05:00

 

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

Re: FormSpec Gurus... help please

by tbillion » Fri Nov 27, 2015 14:43

hate to be a pill but is there more or better examples?

or more to the point why is the player getting the call back? the abm has the form spec and needs the data...

or if you have form spec in an abm, and you have this 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
   meta:set_string("formspec",
         "size[20,11]"..
         "list[current_name;main;0,0;1,4;]"..
         "item_image[1,0;1,1;default:coal_lump]"..
         "item_image[1,1;1,1;default:cobble]"..
         "item_image[1,2;1,1;default:torch]"..
         "item_image[1,3;1,1;default:rail]"..
         "field[3,1;2,1;shaftdepth;'Depth of Shaft';100]"..
         "button[5,0.70;2,1;drillbutton;Drill]"..
         "list[current_name;inv;2,4;18,4;]"..
         "list[current_player;main;2,9;16,2;]")
   meta:set_string("infotext", "Road Paver Machine - " .. fuel)
   meta:set_string("fuel", fuel)
   local inv = meta:get_inventory()
   inv:set_size("inv", 18*4)
   inv:set_size("main", 1*4)


can you still put the form name in there?
i sort of see why it says register_on_player_receive_fields its basically saying when the player performs action get fields right?
 

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

Re: FormSpec Gurus... help please

by tbillion » Fri Nov 27, 2015 14:52

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_player_receive_fields(function(player, formname, fields)
   if formname == "default:team_choose" then -- Replace this with your form name
      print("Player "..player:get_player_name().." submitted fields "..dump(fields))
   end
end)


maybe i have the answer .. shall find out and return
 

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

Re: FormSpec Gurus... help please

by rubenwardy » Fri Nov 27, 2015 14:57

Node callbacks don't call register on formspec submit, they call a callback in the node's definition. See the node part of that chapter, I think there is some info there.

But yeah, I'm planning on adding more examples.
 

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

Re: FormSpec Gurus... help please

by tbillion » Fri Nov 27, 2015 15:10

nope but i messed it up a few times. i think im looking for something like this .. its from pipe works, im goinfg to study it and let ya know what i figure out.. sofar it makes no sense.

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)
      if not pipeworks.may_configure(pos, sender) then return end
      local meta = minetest.get_meta(pos)
      if fields.on then
         update_meta(meta, false)
         minetest.get_node_timer(pos):stop()
      elseif fields.off then
         if update_meta(meta, true) then
            start_crafter(pos)
         end
      end
   end,
 

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

Re: FormSpec Gurus... help please

by tbillion » Fri Nov 27, 2015 15:46

eight examples later im going the right way .... heres what i got

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
   meta:set_string("formspec",
         "size[20,11]"..
         "list[current_name;main;0,0;1,4;]"..
         "item_image[1,0;1,1;default:coal_lump]"..
         "item_image[1,1;1,1;default:cobble]"..
         "item_image[1,2;1,1;default:torch]"..
         "item_image[1,3;1,1;default:rail]"..
         "field[3,1;2,1;shaftdepth;'Depth of Shaft';100]"..
         "button[5,0.70;2,1;drillbutton;Drill]"..
         "list[current_name;inv;2,4;18,4;]"..
         "list[current_player;main;2,9;16,2;]")
   meta:set_string("infotext", "Road Paver Machine - " .. fuel)
   meta:set_string("fuel", fuel)
   local inv = meta:get_inventory()
   inv:set_size("inv", 18*4)
   inv:set_size("main", 1*4)


thats the form spec

this is how i handle the data...

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.env:get_meta(pos);
      fields.text = fields.text or ""
      meta:set_string("depth", fields.shaftdepth)
      print("ishotthe sherrif")
   end,


have to put a little clapton in the debug, clapton and marley... lmao

from here i know how to get the data from meta:string_get and set

the only thing i cant figure out now is how to make the on recieve data reference a function in the same module.. i keep getting :

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
init.lua:423: attempt to index global 'tbmroads' (a nil value)
 

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

Re: FormSpec Gurus... help please

by tbillion » Fri Nov 27, 2015 16:00

why if there is a number in the form spec and it works when i press the button do i get this error when i press escape to exit the form

[code]init.lua:434: attempt to concatenate field 'shaftdepth' (a nil value)[/code\]
 

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

Re: FormSpec Gurus... help please

by tbillion » Fri Nov 27, 2015 16:18

got it to work .. will post results so that others who may have this problem can work through it ... in a minute
 

tbillion
Member
 
Posts: 189
Joined: Wed Apr 03, 2013 16:07

Re: FormSpec Gurus... help please

by tbillion » Fri Nov 27, 2015 17:51

formspec to get the information.
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
tbmroad.placetbmroad = function(pos, fuel)
   -- will correctly pace a tbmroad at the position indicated
   local meta = minetest.env:get_meta(pos)
   meta:set_string("formspec",
         "size[20,11]"..
         "list[current_name;main;0,0;1,4;]"..
         "item_image[1,0;1,1;default:coal_lump]"..
         "item_image[1,1;1,1;default:cobble]"..
         "item_image[1,2;1,1;default:torch]"..
         "item_image[1,3;1,1;default:rail]"..
         "field[3,1;2,1;shaftdepth;'Depth of Shaft';100]"..
         "button[5,0.70;2,1;drillbutton;Drill]"..
         "list[current_name;inv;2,4;18,4;]"..
         "list[current_player;main;2,9;16,2;]")
   meta:set_string("infotext", "Road Paver Machine - " .. fuel)
   meta:set_string("fuel", fuel)
   local inv = meta:get_inventory()
   inv:set_size("inv", 18*4)
   inv:set_size("main", 1*4)
end

handler to put data from formspec to nodes meta data... the trick to this is the if switch that rules out nil data. if you dont have that when you close the form the info goes to nil and you get erros, or in my case a block crushing crazy machine that tears up 10000 blocks as you blink.

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.env:get_meta(pos);
      if fields.shaftdepth ~= nil then
         local shaftdepth = tonumber(fields.shaftdepth)
         meta:set_string("depth", shaftdepth)
      end
   end,
 

User avatar
kaadmy
Member
 
Posts: 627
Joined: Thu Aug 27, 2015 23:07
GitHub: kaadmy
IRC: KaadmY
In-game: KaadmY kaadmy NeD

Re: FormSpec Gurus... help please

by kaadmy » Fri Nov 27, 2015 19:26

That still might not work sometimes.
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
function on_receive_fields(pos, formname, fields, sender)
    local meta = minetest.get_meta(pos)
    if fields.shaftdepth then
        local shaftdepth = tonumber(fields.shaftdepth) or 0
        meta:set_string("depth", shaftdepth)
    end
end

I'm not sure how tonumber acts when given a parameter that can't be converted to a number, so it should be set to 0 if it returns nil.
minetest.get_meta is the correct way, I think. minetest.env:get_meta should also work, somebody correct me if I'm wrong about this.
Never paint white stripes on roads near Zebra crossings.
 

blert2112
Member
 
Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

Re: FormSpec Gurus... help please

by blert2112 » Sun Dec 13, 2015 03:16

kaadmy wrote:Inventory slot tooltips are not configurable, and you can only change ones that you manually supply, like the ones on buttons, fields, etc.

I can now, yay! I added a couple of lines to the engine source to allow me to do it.
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron