[swap_node]Probable typo…

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

[swap_node]Probable typo…

by Grossam » Post

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: 63
Joined: Sun Apr 02, 2017 07:21
GitHub: Grossam
IRC: Grossam
In-game: Grossam
Location: Bourges
Contact:

Re: [swap_node]Probable typo…

by Grossam » Post

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
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: [swap_node]Probable typo…

by Desour » Post

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.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

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

Re: [swap_node]Probable typo…

by Grossam » Post

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
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: [swap_node]Probable typo…

by Desour » Post

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
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

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

Re: [swap_node]Probable typo…

by Grossam » Post

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
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: [swap_node]Probable typo…

by Desour » Post

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.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

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

Re: [swap_node]Probable typo…

by Grossam » Post

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests