[swap_node]Probable typo…

User avatar
Grossam
Member
 
Posts: 23
Joined: Sun Apr 02, 2017 07:21
Location: Bourges
GitHub: Grossam
IRC: Grossam
In-game: Grossam

[swap_node]Probable typo…

by Grossam » Sat May 04, 2019 06:00

Hi ! Here's a code I'm working on : https://pastebin.com/p33eVDNd

The minetest swap_node call at lign 37 isn't executed, and I can't figure why.

Maybe a fresh look could help. Thank you ;-)
Gloire à qui, n'ayant pas d'idéal sacro-saint,
Se borne à ne pas trop emmerder ses voisins.
 

User avatar
Grossam
Member
 
Posts: 23
Joined: Sun Apr 02, 2017 07:21
Location: Bourges
GitHub: Grossam
IRC: Grossam
In-game: Grossam

Re: [swap_node]Probable typo…

by Grossam » Sat May 04, 2019 21:45

Ok ! I did some tests, commenting line 43, and it's no typo : line 37 is executed, but line 43, the next swap is executed immediatly after. So the palm_scanner_checking node isn't there long enough to be seen.

It's strange : the two swaps should be separated by a 1.5 secondes delay (as sound_play() eventually are) but line 43 seems to ignore the small waiting routine.

Has someone an idea about the way I could avoid that strange behaviour ?
Gloire à qui, n'ayant pas d'idéal sacro-saint,
Se borne à ne pas trop emmerder ses voisins.
 

User avatar
DS-minetest
Member
 
Posts: 1075
Joined: Thu Jun 19, 2014 19:49
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
GitHub: DS-Minetest
In-game: DS

Re: [swap_node]Probable typo…

by DS-minetest » Sun May 05, 2019 16:02

Use minetest.after.

I guess this has something to do with threads and when the server sends mapblocks.

Anyway, if you block the one thread that executes lua, you'll make big problems for other mods as well. Nothing can be executed while you do your loop there, that's bad. Use minetest.after.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
Grossam
Member
 
Posts: 23
Joined: Sun Apr 02, 2017 07:21
Location: Bourges
GitHub: Grossam
IRC: Grossam
In-game: Grossam

Re: [swap_node]Probable typo…

by Grossam » Sun May 05, 2019 17:09

You just saved my life : now it works just fine !

Here's my new code :

Code: Select all
-- on_rightclick
-- player is a player object
local function check_owner(pos, node, player, itemstack, pointed_thing)
   local meta = minetest.get_meta(pos)
   local owner = meta:get_string("owner")
   local tested_player = player:get_player_name()
   minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_checking", param2 = node.param2})
   minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0})
   minetest.chat_send_player(tested_player, "Checking : please wait.")

   -- wait for a bit please !
   minetest.after(1.5, function(pos, node, tested_player, owner)
      if tested_player == owner then
         minetest.sound_play("scifi_nodes_access_granted", {max_hear_distance = 8, pos = pos, gain = 1.0})
         minetest.chat_send_player(tested_player, "Access granted !")
         minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_on", param2 = node.param2})
         mesecon.receptor_on(pos, get_switch_rules(node.param2))
         minetest.get_node_timer(pos):start(2)
      else
         minetest.chat_send_player(tested_player, "Access refused !")
         minetest.sound_play("scifi_nodes_access_refused", {max_hear_distance = 8, pos = pos, gain = 1.0})
         minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2})
      end
   end, pos, node, tested_player, owner) -- end of anonymous function
end
Gloire à qui, n'ayant pas d'idéal sacro-saint,
Se borne à ne pas trop emmerder ses voisins.
 

User avatar
DS-minetest
Member
 
Posts: 1075
Joined: Thu Jun 19, 2014 19:49
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
GitHub: DS-Minetest
In-game: DS

Re: [swap_node]Probable typo…

by DS-minetest » Mon May 06, 2019 11:02

Note that the node might have changed during the 1.5 seconds. Eg. someone could have dug it. Ergo more checks would be needed in the after function.

Anyway, I think, in your particular case, it would be better to use node timers.
Something like
on_rightclick: swap the node, save player name in node meta, start node timer
on_timer of swapped node: swap again, do the other stuff
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
Grossam
Member
 
Posts: 23
Joined: Sun Apr 02, 2017 07:21
Location: Bourges
GitHub: Grossam
IRC: Grossam
In-game: Grossam

Re: [swap_node]Probable typo…

by Grossam » Mon May 06, 2019 13:41

And what if I just set diggable = false ?

Il already use a timer ton go back from "on" node to "off" node.
Gloire à qui, n'ayant pas d'idéal sacro-saint,
Se borne à ne pas trop emmerder ses voisins.
 

User avatar
DS-minetest
Member
 
Posts: 1075
Joined: Thu Jun 19, 2014 19:49
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
GitHub: DS-Minetest
In-game: DS

Re: [swap_node]Probable typo…

by DS-minetest » Mon May 06, 2019 18:26

There are things that ignore if it's undiggable. Furthermore, it would be a bit weird if the node was indestructible while being in checking mode.

You can use a different on_timer for "scifi_nodes:palm_scanner_checking" than for "scifi_nodes:palm_scanner_on".
Another problem of minetest.after is that if the game ends while it afters, the after function is not called.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
Grossam
Member
 
Posts: 23
Joined: Sun Apr 02, 2017 07:21
Location: Bourges
GitHub: Grossam
IRC: Grossam
In-game: Grossam

Re: [swap_node]Probable typo…

by Grossam » Mon May 06, 2019 18:32

Yep ! I'll try to follow your advice. It should give a cleaner code.
Gloire à qui, n'ayant pas d'idéal sacro-saint,
Se borne à ne pas trop emmerder ses voisins.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest