register_on_player_receive_fields doesn't seem to be working

Post Reply
Immurator
New member
Posts: 7
Joined: Tue Jan 13, 2015 13:33
In-game: Immurator

register_on_player_receive_fields doesn't seem to be working

by Immurator » Post

I'm having problems with minetest.register_on_player_receive_fields

I'm creating a simple formspec to allow user input, but code I place inside of register_on_player_receive_fields never executes. After trying several things, I removed all my code related to the formspec and added the example code from the modding book:

Code: Select all

-- Show form when the /formspec command is used.
minetest.register_chatcommand("formspec", {
    func = function(name, param)
        minetest.show_formspec(name, "mymod:form",
                "size[4,3]" ..
                "label[0,0;Hello, " .. name .. "]" ..
                "field[1,1.5;3,1;name;Name;]" ..
                "button_exit[1,2;2,1;exit;Save]")
    end
})

-- Register callback
minetest.register_on_player_receive_fields(function(player, formname, fields)
    if formname ~= "mymod:form" then
        -- Formname is not mymod:form,
        -- exit callback.
        return false
    end

    -- Send message to player.
    minetest.chat_send_player(player:get_player_name(), "You said: " .. fields.name .. "!")

    -- Return true to stop other minetest.register_on_player_receive_fields
    -- from receiving this submission.
    return true
end)
When I click on the "Save" button on the formspec, it closes properly, but instead of executing the code inside of the callback, it outputs this:

Code: Select all

Inventory fields 3: player=singleplayer, fields={
 exit = "Save",
 name = "Test",
 quit = "true"
}
Inventory fields 2: player=singleplayer, fields={
 exit = "Save",
 name = "Test",
 quit = "true"
}
Anyone seen this before or recognize the novice error I'm making?

Thanks!

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: register_on_player_receive_fields doesn't seem to be wor

by Krock » Post

I've seen it and the solution is very simple. You're using the "minimal" game, which exists for core feature tests and should not be used in regular worlds.
Instead, select "Minetest Game" in the Singleplayer tab and create a new world with it. If you're using minimal on purpose, then remove these lines in games/minimal/mods/experimental/init.lua .
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Phoenixflo44
Member
Posts: 639
Joined: Fri Jul 28, 2017 15:01
In-game: EvilPhoenix
Location: Behind my PC, in Germany

Re: register_on_player_receive_fields doesn't seem to be wor

by Phoenixflo44 » Post

And if the minetest_game doesn't exist, you should get it. There are also many other games.
Spoiler
I hate my life

Immurator
New member
Posts: 7
Joined: Tue Jan 13, 2015 13:33
In-game: Immurator

Re: register_on_player_receive_fields doesn't seem to be wor

by Immurator » Post

That was it. Thank you so much!

Thanks also for the extra detail about the experimental code. Very helpful.

User avatar
Phoenixflo44
Member
Posts: 639
Joined: Fri Jul 28, 2017 15:01
In-game: EvilPhoenix
Location: Behind my PC, in Germany

Re: register_on_player_receive_fields doesn't seem to be wor

by Phoenixflo44 » Post

No problem.
Have fun at Minetest and in the forum.
Spoiler
I hate my life

User avatar
Phoenixflo44
Member
Posts: 639
Joined: Fri Jul 28, 2017 15:01
In-game: EvilPhoenix
Location: Behind my PC, in Germany

Re: register_on_player_receive_fields doesn't seem to be wor

by Phoenixflo44 » Post

But if again is a problem then post it at "Problems "
Spoiler
I hate my life

Immurator
New member
Posts: 7
Joined: Tue Jan 13, 2015 13:33
In-game: Immurator

Re: register_on_player_receive_fields doesn't seem to be wor

by Immurator » Post

Ah, ok. Thanks! Didn't see that section. Appreciate it. :)

User avatar
Phoenixflo44
Member
Posts: 639
Joined: Fri Jul 28, 2017 15:01
In-game: EvilPhoenix
Location: Behind my PC, in Germany

Re: register_on_player_receive_fields doesn't seem to be wor

by Phoenixflo44 » Post

True to me exactly. I didn't know what to do.
Spoiler
I hate my life

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: register_on_player_receive_fields doesn't seem to be wor

by Krock » Post

Immurator wrote:That was it. Thank you so much!
No problem, I'm glad that it solved your issue.
Phoenixflo44 wrote:But if again is a problem then post it at "Problems "
It's rather modding-related than an actual Minetest issue because minimal exists for Minetest development, not for regular worlds. Also consider editing your previous post instead of posting an one-liner in the future - it consumes visual space and takes longer to see the relevant information. For some reason we have this button. (Fancy curvy line not included)
Image
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

Immurator
New member
Posts: 7
Joined: Tue Jan 13, 2015 13:33
In-game: Immurator

Re: register_on_player_receive_fields doesn't seem to be wor

by Immurator » Post

Thanks, Krock. Will do.

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests