formspec deficiency and inconsistency with documentation

kpo
Member
 
Posts: 38
Joined: Sun Mar 31, 2013 19:01

formspec deficiency and inconsistency with documentation

by kpo » Wed May 01, 2013 22:46

I have tried to use the formspec as it is advertised:
http://dev.minetest.net/minetest.register_node#on_receive_fields

Specifically the "fields" :
fields — The names and values of the form's fields, as a table: {name1 = value1, name2 = value2, ...}

is in my opinion not implemented as it states.

Take an image_button for example. I would expect to be able to set a name:value pair on my buttons so that I don't have to have (potentially large) if;then;else;end block afterwards to get the value of dome button.
Also not all the fields in the form is returned, just any "field" type fields and the very button I pressed.

I claim this is a bug because if the formspec worked as the on_receive_fields states I would be able to make button groups like this pseudocode:
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
image_button(...;"group1";val__left";mylabel)
image_button(...;"group1";val__right";myotherlabel)
...
image_button(...;"group2";val__accept";mythirdlabel)
...


In my code I would now simply get the value of fields.group1 and act on that. The way it is implemented now I have to search the complete list of declared button names to first figure out which one was pressed, then provide the value for further processing. This is rather inefficient and requires more code than would be needed if it worked right.

I think this code in the guiFormSpecMenu.cpp is not doing the right thing:
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
        else if(type == "item_image_button")
        {
            v2s32 pos = padding;
            pos.X += stof(f.next_esc(",")) * (float)spacing.X;
            pos.Y += stof(f.next_esc(";")) * (float)spacing.Y;
            v2s32 geom;
            geom.X = (stof(f.next_esc(",")) * (float)spacing.X)-(spacing.X-imgsize.X);
            geom.Y = (stof(f.next_esc(";")) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
            rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);       
            std::string fimage = f.next_esc(";");
            std::string fname = f.next_esc(";");
            std::string flabel = f.next_esc("]");


The fname string is not providing a key=value for the FieldSpec later.

This is easily reproducible, just look at any mod using buttons/image_buttons on a formspec (noncubic,unified_inventory,circular_saw etc.).

I propose a change of the formspec for buttons (and all other elements wanting to return a key:value pair) such that a button must be defined like:
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
(image_)button[X,Y;W,H;image;name;value;label]

The value and label is optional this way like the label is today.

Any feedback on this is appreciated.
 

Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 9 guests

cron