-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
39 lines (38 loc) · 1.51 KB
/
main.lua
File metadata and controls
39 lines (38 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
--https://pastebin.com/xT2S4feR
---@diagnostic disable: undefined-global
--Computer1 is in the elevator
--Computer2 is the main computer to process the msg
--Computer3 can reverse the direction of rotation or not
--Computer4 can control the start of the elevator or not
--Computer5,6,7,8.... is on the floor accordingly
--how many floors you want,how many Computer5,6,7,8...you need
--author Ausert
rednet.open("left")
local CurFloorNum=0 --CurrentFloorNumber plz equal with the real condition or maybe get bug
local DstFloorNum=0 --DestinationFloor inited recommended
while true do
local id,msg=rednet.receive("call")
--process the request when player is in the lift and want to up and down
--or call the lift and wait
--the first letter is A means the same function request as Computer1
--but Computerid is not Computer1 so we need use A to distinguish
if(id==1 or string.sub(msg,1,1)=='A') then
if(string.sub(msg,1,1)=='A') then
msg=string.sub(msg,2)
end
DstFloorNum=tonumber(msg)
if(DstFloorNum<CurFloorNum) then
rednet.send(3,"1","reverse")
rednet.send(4,"0","control")
elseif(DstFloorNum>CurFloorNum) then
rednet.send(3,"0","reverse")
rednet.send(4,"0","control")
end
--update the Current Floor number of the lift
else
CurFloorNum=tonumber(msg)
if(CurFloorNum==DstFloorNum) then
rednet.send(4,"1","control")
end
end
end