Swap Node and Remove/Hide Formspec

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

Swap Node and Remove/Hide Formspec

by octacian » Tue Jul 12, 2016 20:40

I'm working on a (functional) computers mod. When the user enter the command "shutdown," the computer used my swap node functions (see here) to change to the off node. However, even though after the swap I use meta:set_string("formspec", nil) the formspec will still show when off after the player exits. I'd also like a way to hide the formspec automatically rather than the player having to press a button or <esc>.

I could use show_formspec on rightclick instead of the normal formspec meta, but I don't think that would be as efficient. I'm gonna have to do that anyway (I assume?) for other menus/inventories within the computer. However, I still am not sure it is possible to easily hide them.

One other issue that I mentioned in my previous post, is that swap node does not keep the facedir. If you can tell me how to keep the facedir with swap node, please do so on my other post to keep everything together (for other people's possible reference).
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

Re: Swap Node and Remove/Hide Formspec

by Sokomine » Thu Jul 28, 2016 16:09

In general, doing show_formspec on rightclick ought to be fast enough, especially when it's a node that will display a specific menu anyway. The usually faster pre-defined formspec is mostly needed for things that come with an inventory and where quick access is highly desirable (like locked chests, though those seem to have become faster anyway).
Just provide swap_node with the facedir parameter. You need to read the node first in order to determine the value.
A list of my mods can be found here.
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Swap Node and Remove/Hide Formspec

by everamzah » Thu Jul 28, 2016 16:31

Krock showed me this trick:

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 node = minetest.get_node(pos)
node.name = "mod:another_node"
minetest.swap_node(pos, node)

Which preserves the facedir.
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Swap Node and Remove/Hide Formspec

by everamzah » Thu Jul 28, 2016 17:24

I could use show_formspec on rightclick instead of the normal formspec meta...


This is actually how the locked chest does it. The regular chest does not. If you want to have a formspec send a field that calls itself (dynamic menu, for example), then this is how you'd do it.

There are many mods that do this. You can look at my books mod for an example.
 

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

Re: Swap Node and Remove/Hide Formspec

by octacian » Thu Jul 28, 2016 17:43

I already figured out swap_node, thanks anyway.

I probably will use show formspec when I get time to switch to it. Is there something like hide_formspec?

Thanks.
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

Re: Swap Node and Remove/Hide Formspec

by everamzah » Thu Jul 28, 2016 20:13

There's button_exit[]. Formspecs are escaped using the Escape key, or double-clicking outside the form.

Parsing the fields you'll see quit=true whenever it occurs.

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)
  print(formname)
  print(dump(fields)
end)
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 62 guests

cron