Question : How to make inevitable formspec ?

Post Reply
User avatar
LMD
Member
Posts: 1396
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Question : How to make inevitable formspec ?

by LMD » Post

So I made some nice formspecs and added receive_fields functions. Works fine. However, player can still skip using escape. How to disable that ??
My stuff: Projects - Mods - Website

User avatar
octacian
Member
Posts: 597
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian
Location: Canada

Re: Question : How to make inevitable formspec ?

by octacian » Post

Listen for fields.quit == "true" and reopen the formspec when it is received.

Be careful though, the quit field is also sent by button_exit and the likes, so you should put the check for fields.quit at the end of all your other logic in order to ensure that you don't reopen the formspec when you don't want to.

For example:

Code: Select all

local function show_form(player)
	local name = player:get_player_name()
	minetest.show_formspec(name, "stay_open", "size[5, 5]button[0,0;3,1;nothing;I am a pointless button]")
end

minetest.register_on_joinplayer(function(player)
	show_form(player)
end)

minetest.register_on_player_receive_fields(function(player, formname, fields)
	if formname == "stay_open" then
		if fields.nothing then
			-- Do something with the button input
			-- This is just an example, other input handles can be added as elseif clauses.
		elseif fields.quit == "true" then
			-- Reopen formspec
			minetest.after(0.1, function() show_form(player) end)
		end
	end
end)

minetest.register_chatcommand("show_form", {
	func = function(name)
		show_form(minetest.get_player_by_name(name))
	end,
})
The pause with minetest.after is simply because Minetest is often a bit finicky with when it will allow the form to be shown. I believe I got it working before without it, but I can't seem to find the code.
Last edited by octacian on Mon Jun 18, 2018 19:55, edited 3 times in total.
MicroExpansion, Working Computers, All Projects - Check out my YouTube channel! (octacian)
I'm currently inactive in the Minetest community! So if I don't respond, that's why.

User avatar
LMD
Member
Posts: 1396
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Re: Question : How to make inevitable formspec ?

by LMD » Post

Oh thanks for quick answer :) Took only 2 mins !
My stuff: Projects - Mods - Website

User avatar
octacian
Member
Posts: 597
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian
Location: Canada

Re: Question : How to make inevitable formspec ?

by octacian » Post

I've updated my original reply with some example code that should get you started. Minetest is really weird with when it will allow minetest.show_formspec to be called. I'm really not sure why, but.

Now, it is also worth noting that the player can hold the escape key until the pause menu shows up, and then the formspec will actually be exited anyway. But the only way to get around this is to use a globalstep to reshow the formspec if a particular player meta field does not exist, for example.
MicroExpansion, Working Computers, All Projects - Check out my YouTube channel! (octacian)
I'm currently inactive in the Minetest community! So if I don't respond, that's why.

User avatar
LMD
Member
Posts: 1396
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Re: Question : How to make inevitable formspec ?

by LMD » Post

I also thought of Globalstep at first, but then Krock told me it was bad for networking, AFA i understood.
And he is core dev, so I guess his is better...
My stuff: Projects - Mods - Website

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

Re: Question : How to make inevitable formspec ?

by Krock » Post

LMD wrote:I also thought of Globalstep at first, but then Krock told me it was bad for networking.
A short addition to this statement: globalsteps are not ideal because they re-send a formspec more than 10 times per second (0.09s interval by default). This causes unnecessary traffic and also makes clicking a button difficult when the focus is lost in such a fast interval.
It's also not possible to rely only on "fields.quit" or any such callbacks because the client will always find a way to evade the formspec by spamming ESC, like octacian already mentioned before. So re-send the formspec in an interval of a second or slower (minetest.after maybe) if you really want to penetrate the clients with that instead of offering a cheap "spectate only" mode or "kick on disagree". Latter suggestions would probably be more appreciated by players than a formspec from which they can't escape easily (i.e. pressing ESC, double click outside).
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

u34

Re: Question : How to make inevitable formspec ?

by u34 » Post

{
a long time ago mainframes from ibm sends the masks i suppose only the fields which has been changed, not the hole mask with all text and input elements? I do not know the code of the minetest source, but can we change this for a performanter speed of transfer? maybe i should read the relevante source code to find the answer of my question.
}
+1
# keep on the good work #

hajo
Member
Posts: 606
Joined: Thu Oct 13, 2016 10:45
Location: DE
Contact:

Re: Question : How to make inevitable formspec ?

by hajo » Post

LMD wrote:formspecs .. player can still skip using escape. How to disable that ?
Why do you need that ?

Forcing the user / player to do something, or react RIGHT NOW
is very annoying, and bad UI-design in general.

User avatar
LMD
Member
Posts: 1396
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Re: Question : How to make inevitable formspec ?

by LMD » Post

So, in magic-ctf there will be (1) "Agree to rules" formspec. This should OF COURSE not be evitable. And then there's the "select skills" formspec : you got 30 points to invest in different skills, each skill upgradeable 30 times. Conclusion : To make gameplay fair, I have to force everybody to USE all of that 30 points. Else some noobs may dont do so.
Also, I am showing that skill orientation on_joinplayer, which is the right time; the decision has to be made before play, and not at anytime, and if you wanna change, just rejoin. If it was evitable, I'd have to make an option for players to "reshow" it, such as key press or item. But this means more effort and is less good; due to the noobs as well as the fact it simply is the ONLY senseful solution to have to orientate on JOIN.
My stuff: Projects - Mods - Website

hajo
Member
Posts: 606
Joined: Thu Oct 13, 2016 10:45
Location: DE
Contact:

Re: Question : How to make inevitable formspec ?

by hajo » Post

LMD wrote:"Agree to rules" formspec. This should OF COURSE not be evitable.
No need to force formspec - just don't give interact until done..
"select skills" formspec .. force everybody to USE all of that 30 points.
It shouldn't be your problem if someone wants to play with a handicap.
showing that skill orientation on_joinplayer, which is the right time ..
ONLY senseful solution to have to orientate on JOIN.
Simpler: make a chat-command, eg. '/skills'.

No need to change how formspec works.

Post Reply

Who is online

Users browsing this forum: SkyBuilder1717 and 5 guests