Skip to content

Commit 0b3d6b3

Browse files
committed
Shortening of Screen.lua
1 parent 5967123 commit 0b3d6b3

File tree

2 files changed

+78
-84
lines changed

2 files changed

+78
-84
lines changed

‎Programs/Deutsch/Screen.lua‎

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ function conf.setlights()
5252
button.setTable("in allen ausschalten", "turn all off", 14, 29, 17, 52, Green)
5353
end
5454

55-
function conf.statelights(state)
55+
function conf.statelights(state, room)
5656
if state == "on" then
57-
button.draw(18, 15, 21, 65, Stateonsentence, Green, "Möchten sie es ausschalten?")
57+
button.draw(18, 15, 21, 65, button2[room]["stateonsentence"], Green, "Möchten sie es ausschalten?")
5858
button.setTable("Ja", "turn off", 22, 22, 25, 39, Green)
5959
end
6060
if state == "off" then
61-
button.draw(18, 15, 21, 65, Stateoffsentence, Red, "Möchten sie es einschalten?")
61+
button.draw(18, 15, 21, 65, button2[room]["stateoffsentence"], Red, "Möchten sie es einschalten?")
6262
button.setTable("Ja", "turn on", 22, 22, 25, 39, Green)
6363
end
6464
button.setTable("Nein", "no", 22, 42, 25, 59, Green)
@@ -81,13 +81,13 @@ function conf.setdoors()
8181
doorbutton.setTable("Haus abschließen", "lock house", 11, 29, 14, 52, "Das Haus wurde abgeschlossen und der Alarm aktiviert!", nil, Green)
8282
end
8383

84-
function conf.statedoors(state)
84+
function conf.statedoors(state, door)
8585
if state == "opened" then
86-
button.draw(14, 20, 17, 60, Sos, Red, "Möchten sie die Tür schließen?")
86+
button.draw(14, 20, 17, 60, button2[door]["opensentence"], Red, "Möchten sie die Tür schließen?")
8787
button.setTable("Ja", "close", 18, 22, 21, 39, Green)
8888
end
8989
if state == "closed" then
90-
button.draw(14, 20, 17, 60, Scs, Green, "Möchten sie die Tür öffnen?")
90+
button.draw(14, 20, 17, 60, button2[door]["closesentence"], Green, "Möchten sie die Tür öffnen?")
9191
button.setTable("Ja", "open", 18, 22, 21, 39, Green)
9292
end
9393
button.setTable("Nein", "no", 18, 42, 21, 59, Green)
@@ -180,39 +180,39 @@ end
180180

181181
function button.setTable(name, func, miny, minx, maxy, maxx, color)
182182
button.draw(miny, minx, maxy, maxx, name, color)
183-
button2[name] = {}
184-
button2[name]["name"] = name
185-
button2[name]["func"] = func
186-
button2[name]["miny"] = miny
187-
button2[name]["minx"] = minx
188-
button2[name]["maxy"] = maxy
189-
button2[name]["maxx"] = maxx
183+
button2[func] = {}
184+
button2[func]["name"] = name
185+
button2[func]["func"] = func
186+
button2[func]["miny"] = miny
187+
button2[func]["minx"] = minx
188+
button2[func]["maxy"] = maxy
189+
button2[func]["maxx"] = maxx
190190
end
191191

192192
function lightbutton.setTable(name, func, miny, minx, maxy, maxx, stateonsentence, stateoffsentence, color)
193193
button.draw(miny, minx, maxy, maxx, name, color)
194-
button2[name] = {}
195-
button2[name]["name"] = name
196-
button2[name]["func"] = func
197-
button2[name]["miny"] = miny
198-
button2[name]["minx"] = minx
199-
button2[name]["maxy"] = maxy
200-
button2[name]["maxx"] = maxx
201-
button2[name]["stateonsentence"] = stateonsentence
202-
button2[name]["stateoffsentence"] = stateoffsentence
194+
button2[func] = {}
195+
button2[func]["name"] = name
196+
button2[func]["func"] = func
197+
button2[func]["miny"] = miny
198+
button2[func]["minx"] = minx
199+
button2[func]["maxy"] = maxy
200+
button2[func]["maxx"] = maxx
201+
button2[func]["stateonsentence"] = stateonsentence
202+
button2[func]["stateoffsentence"] = stateoffsentence
203203
end
204204

205205
function doorbutton.setTable(name, door, miny, minx, maxy, maxx, stateopensentence, stateclosesentence, color)
206206
button.draw(miny, minx, maxy, maxx, name, color)
207-
button2[name] = {}
208-
button2[name]["name"] = name
209-
button2[name]["func"] = door
210-
button2[name]["miny"] = miny
211-
button2[name]["minx"] = minx
212-
button2[name]["maxy"] = maxy
213-
button2[name]["maxx"] = maxx
214-
button2[name]["opensentence"] = stateopensentence
215-
button2[name]["closesentence"] = stateclosesentence
207+
button2[door] = {}
208+
button2[door]["name"] = name
209+
button2[door]["func"] = door
210+
button2[door]["miny"] = miny
211+
button2[door]["minx"] = minx
212+
button2[door]["maxy"] = maxy
213+
button2[door]["maxx"] = maxx
214+
button2[door]["opensentence"] = stateopensentence
215+
button2[door]["closesentence"] = stateclosesentence
216216
end
217217

218218
function Touch(usecase)
@@ -232,11 +232,6 @@ function Touch(usecase)
232232
if X >= data["minx"] and X <= data["maxx"] then
233233
button.draw(data["miny"], data["minx"], data["maxy"], data["maxx"], data["name"], Red)
234234
Func = data["func"]
235-
Stateonsentence = data["stateonsentence"]
236-
Stateoffsentence = data["stateoffsentence"]
237-
Sos = data["opensentence"]
238-
Scs = data["closesentence"]
239-
Action = data["action"]
240235
end
241236
end
242237
end
@@ -253,7 +248,7 @@ function light()
253248
if Func == "turn all off" then
254249
else Room = Func
255250
_, _, _, _, _, State = event.pull("modem_message")
256-
conf.statelights(State)
251+
conf.statelights(State, Room)
257252
Touch()
258253
if Func == "turn off" or Func == "turn on" then modem.send(server, Port, "light", Room, Func)
259254
local _, _, _, _, _, check = event.pull("modem_message")
@@ -286,7 +281,7 @@ function door()
286281
modem.send(server, Port, "door", Func)
287282
Doorname = Func
288283
local _, _, _, _, _, status = event.pull("modem_message")
289-
conf.statedoors(status)
284+
conf.statedoors(status, Doorname)
290285
Touch()
291286
if Timeout2 then
292287
return
@@ -407,24 +402,26 @@ function lock.doorcode(action, miny, minx)
407402
if Timeout2 then return end
408403
modem.send(server, Port, "door", Doorname, action, Pass)
409404
local _, _, _, _, _, codecheck, check = event.pull("modem_message")
405+
lock.codecheck(codecheck, miny, minx)
410406
if codecheck == "correct" then
411-
lock.codecheck(codecheck, miny, minx)
412407
conf.checkdooraction(check, miny)
413408
end
414-
if codecheck == "wrong" then lock.codecheck(codecheck, miny, minx) os.sleep(1) lock.doorcode(action, miny, minx) end
409+
if codecheck == "wrong" then
410+
os.sleep(1)
411+
lock.doorcode(action, miny, minx)
412+
end
415413
end
416414

417415
function lock.alarmcode(action, miny, minx)
418416
lock.code(miny, minx, Green)
419417
if Timeout2 then return end
420418
modem.send(server, Port, "alarm", nil, action, Pass)
421419
local _, _, _, _, _, codecheck, check = event.pull("modem_message")
420+
lock.codecheck(codecheck, miny, minx)
422421
if codecheck == "correct" then
423-
lock.codecheck(codecheck, miny, minx)
424422
conf.checkalarm(check, miny)
425423
end
426424
if codecheck == "wrong" then
427-
lock.codecheck(codecheck, miny, minx)
428425
os.sleep(1)
429426
lock.alarmcode(action, miny, minx)
430427
end

‎Programs/English/Screen.lua‎

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ function conf.setlights()
5252
button.setTable("Turn all off", "turn all off", 14, 29, 17, 52, Green)
5353
end
5454

55-
function conf.statelights(state)
55+
function conf.statelights(state, room)
5656
if state == "on" then
57-
button.draw(18, 15, 21, 65, Stateonsentence, Green, "Do you want to turn it off?")
57+
button.draw(18, 15, 21, 65, button2[room]["stateonsentence"], Green, "Do you want to turn it off?")
5858
button.setTable("Yes", "turn off", 22, 22, 25, 39, Green)
5959
end
6060
if state == "off" then
61-
button.draw(18, 15, 21, 65, Stateoffsentence, Red, "Do you want to turn it on?")
61+
button.draw(18, 15, 21, 65, button2[room]["stateoffsentence"], Red, "Do you want to turn it on?")
6262
button.setTable("Yes", "turn on", 22, 22, 25, 39, Green)
6363
end
6464
button.setTable("No", "no", 22, 42, 25, 59, Green)
@@ -81,13 +81,13 @@ function conf.setdoors()
8181
doorbutton.setTable("Lock House", "lock house", 11, 29, 14, 52, "The House was locked and the alarm is activated", nil, Green)
8282
end
8383

84-
function conf.statedoors(state)
84+
function conf.statedoors(state, door)
8585
if state == "opened" then
86-
button.draw(14, 20, 17, 60, Sos, Red, "Do you want to close the door?")
86+
button.draw(14, 20, 17, 60, button2[door]["opensentence"], Red, "Do you want to close the door?")
8787
button.setTable("Yes", "close", 18, 22, 21, 39, Green)
8888
end
8989
if state == "closed" then
90-
button.draw(14, 20, 17, 60, Scs, Green, "Do you want to open the door?")
90+
button.draw(14, 20, 17, 60, button2[door]["closesentence"], Green, "Do you want to open the door?")
9191
button.setTable("Yes", "open", 18, 22, 21, 39, Green)
9292
end
9393
button.setTable("No", "no", 18, 42, 21, 59, Green)
@@ -180,39 +180,39 @@ end
180180

181181
function button.setTable(name, func, miny, minx, maxy, maxx, color)
182182
button.draw(miny, minx, maxy, maxx, name, color)
183-
button2[name] = {}
184-
button2[name]["name"] = name
185-
button2[name]["func"] = func
186-
button2[name]["miny"] = miny
187-
button2[name]["minx"] = minx
188-
button2[name]["maxy"] = maxy
189-
button2[name]["maxx"] = maxx
183+
button2[func] = {}
184+
button2[func]["name"] = name
185+
button2[func]["func"] = func
186+
button2[func]["miny"] = miny
187+
button2[func]["minx"] = minx
188+
button2[func]["maxy"] = maxy
189+
button2[func]["maxx"] = maxx
190190
end
191191

192192
function lightbutton.setTable(name, func, miny, minx, maxy, maxx, stateonsentence, stateoffsentence, color)
193193
button.draw(miny, minx, maxy, maxx, name, color)
194-
button2[name] = {}
195-
button2[name]["name"] = name
196-
button2[name]["func"] = func
197-
button2[name]["miny"] = miny
198-
button2[name]["minx"] = minx
199-
button2[name]["maxy"] = maxy
200-
button2[name]["maxx"] = maxx
201-
button2[name]["stateonsentence"] = stateonsentence
202-
button2[name]["stateoffsentence"] = stateoffsentence
194+
button2[func] = {}
195+
button2[func]["name"] = name
196+
button2[func]["func"] = func
197+
button2[func]["miny"] = miny
198+
button2[func]["minx"] = minx
199+
button2[func]["maxy"] = maxy
200+
button2[func]["maxx"] = maxx
201+
button2[func]["stateonsentence"] = stateonsentence
202+
button2[func]["stateoffsentence"] = stateoffsentence
203203
end
204204

205205
function doorbutton.setTable(name, door, miny, minx, maxy, maxx, stateopensentence, stateclosesentence, color)
206206
button.draw(miny, minx, maxy, maxx, name, color)
207-
button2[name] = {}
208-
button2[name]["name"] = name
209-
button2[name]["func"] = door
210-
button2[name]["miny"] = miny
211-
button2[name]["minx"] = minx
212-
button2[name]["maxy"] = maxy
213-
button2[name]["maxx"] = maxx
214-
button2[name]["opensentence"] = stateopensentence
215-
button2[name]["closesentence"] = stateclosesentence
207+
button2[door] = {}
208+
button2[door]["name"] = name
209+
button2[door]["func"] = door
210+
button2[door]["miny"] = miny
211+
button2[door]["minx"] = minx
212+
button2[door]["maxy"] = maxy
213+
button2[door]["maxx"] = maxx
214+
button2[door]["opensentence"] = stateopensentence
215+
button2[door]["closesentence"] = stateclosesentence
216216
end
217217

218218
function Touch(usecase)
@@ -232,11 +232,6 @@ function Touch(usecase)
232232
if X >= data["minx"] and X <= data["maxx"] then
233233
button.draw(data["miny"], data["minx"], data["maxy"], data["maxx"], data["name"], Red)
234234
Func = data["func"]
235-
Stateonsentence = data["stateonsentence"]
236-
Stateoffsentence = data["stateoffsentence"]
237-
Sos = data["opensentence"]
238-
Scs = data["closesentence"]
239-
Action = data["action"]
240235
end
241236
end
242237
end
@@ -253,7 +248,7 @@ function light()
253248
if Func == "turn all off" then
254249
else Room = Func
255250
_, _, _, _, _, State = event.pull("modem_message")
256-
conf.statelights(State)
251+
conf.statelights(State, Room)
257252
Touch()
258253
if Func == "turn off" or Func == "turn on" then modem.send(server, Port, "light", Room, Func)
259254
local _, _, _, _, _, check = event.pull("modem_message")
@@ -286,7 +281,7 @@ function door()
286281
modem.send(server, Port, "door", Func)
287282
Doorname = Func
288283
local _, _, _, _, _, status = event.pull("modem_message")
289-
conf.statedoors(status)
284+
conf.statedoors(status, Doorname)
290285
Touch()
291286
if Timeout2 then
292287
return
@@ -407,24 +402,26 @@ function lock.doorcode(action, miny, minx)
407402
if Timeout2 then return end
408403
modem.send(server, Port, "door", Doorname, action, Pass)
409404
local _, _, _, _, _, codecheck, check = event.pull("modem_message")
405+
lock.codecheck(codecheck, miny, minx)
410406
if codecheck == "correct" then
411-
lock.codecheck(codecheck, miny, minx)
412407
conf.checkdooraction(check, miny)
413408
end
414-
if codecheck == "wrong" then lock.codecheck(codecheck, miny, minx) os.sleep(1) lock.doorcode(action, miny, minx) end
409+
if codecheck == "wrong" then
410+
os.sleep(1)
411+
lock.doorcode(action, miny, minx)
412+
end
415413
end
416414

417415
function lock.alarmcode(action, miny, minx)
418416
lock.code(miny, minx, Green)
419417
if Timeout2 then return end
420418
modem.send(server, Port, "alarm", nil, action, Pass)
421419
local _, _, _, _, _, codecheck, check = event.pull("modem_message")
420+
lock.codecheck(codecheck, miny, minx)
422421
if codecheck == "correct" then
423-
lock.codecheck(codecheck, miny, minx)
424422
conf.checkalarm(check, miny)
425423
end
426424
if codecheck == "wrong" then
427-
lock.codecheck(codecheck, miny, minx)
428425
os.sleep(1)
429426
lock.alarmcode(action, miny, minx)
430427
end

0 commit comments

Comments
 (0)