SHOW:
|
|
- or go back to the newest paste.
1 | rednet.open("top") | |
2 | monitor = peripheral.find("monitor") | |
3 | monitor.clear() | |
4 | msgTemp = -1 | |
5 | box = peripheral.find("chatBox") | |
6 | ||
7 | - | if id~=nil and msg~=nil then |
7 | + | function monitorShow(message) |
8 | - | print("id"..id.." | message "..msg) |
8 | + | |
9 | - | print(string.len(msg)) |
9 | + | |
10 | monitor.write(message) | |
11 | end | |
12 | - | monitor.write(msg) |
12 | + | |
13 | - | os.sleep(1) |
13 | + | function consummation(_msg) |
14 | rfCons = _msg | |
15 | print(rfCons) | |
16 | value = "" | |
17 | size = string.len(_msg) | |
18 | pow = size-3 | |
19 | print(pow.."p|s"..size) | |
20 | --si c'est au dessus de 0 donc il faut faire une simplification | |
21 | if pow>0 then | |
22 | if size>3 and size<7 then | |
23 | rfCons = _msg/(math.pow(10,3)) | |
24 | value = "k" | |
25 | end | |
26 | if size>6 and size<10 then | |
27 | rfCons = _msg/(math.pow(10,6)) | |
28 | value = "M" | |
29 | end | |
30 | if size>9 and size<13 then | |
31 | rfCons = _msg/(math.pow(10,9)) | |
32 | value = "G" | |
33 | end | |
34 | if size>12 then | |
35 | rfCons = _msg/(math.pow(10,12)) | |
36 | value = "T" | |
37 | end | |
38 | end | |
39 | ||
40 | ||
41 | --message = string.sub(rfCons.."",1,5)..value.."FE/t) | |
42 | --value = value.."FE/t" | |
43 | ||
44 | print(rfCons) | |
45 | ||
46 | --retour de la valeur de la consommation | |
47 | return string.sub(rfCons.."",1,5)..value.."FE/t" | |
48 | end | |
49 | ||
50 | function chatBox(rfCons) | |
51 | event, player, chatItem = os.pullEvent("chat") | |
52 | if chatItem == ".cons" then | |
53 | box.sendMessage(rfCons,"Info Conso") | |
54 | end | |
55 | end | |
56 | ||
57 | while true do | |
58 | id, msg = rednet.receive() | |
59 | rfCons = consummation(msg) | |
60 | --On passe ici que s'il y a changement d'etat | |
61 | if id~=nil and msg~=nil and msg~=msgTemp then | |
62 | monitorShow(rfCons) | |
63 | os.sleep(1) | |
64 | end | |
65 | id, msgTemp = rednet.receive() | |
66 | chatBox(rfCons) | |
67 | end |