From 09c1f038f50404b136ab746a04c93c0b63b78429 Mon Sep 17 00:00:00 2001
From: webdesigner97 <Christian_D_97@gmx.de>
Date: Thu, 24 Apr 2014 19:14:30 +0200
Subject: [PATCH] small improvments

---
 trafficlight/init.lua | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/trafficlight/init.lua b/trafficlight/init.lua
index b33154d..7e6051a 100644
--- a/trafficlight/init.lua
+++ b/trafficlight/init.lua
@@ -57,8 +57,14 @@ streets.tlSwitch = function(def)
 	if not def.pos or not def.to or not streets.tlRythm[def.to] then
 		return
 	end
+	local meta = minetest.get_meta(def.pos)
+	-- Only switch if new state ~= current state
+	if "to" .. meta:get_string("state") == def.to then
+		return
+	end
 	-- Switch the trafficlight
 	for k, v in pairs(streets.tlRythm[def.to]) do
+		minetest.get_meta(def.pos):set_string("state", def.to:gsub("to", ""))
 		minetest.after(v.pauseBefore, function()
 			minetest.swap_node(def.pos, {name = v.name, param2 = minetest.get_node(def.pos).param2})
 		end)