Posted 07 October 2016 - 08:13 PM
Before anything, I'd like to iterate I'm relatively new to Lua, and a complete noob to ComputerCraft; and I'm probably just having a minor problem that can easily be fixed. Nevertheless, I appreciate any attempt to help, successful or unsuccessful.
Here goes:
I'm trying to make a telecommunications network in between several computers (Three, so far), a pocket advanced computer, a main computer which acts like both a server and console, and finally a computer to control my house (Doors, lightning, etc.)
Mainly, my computers are composed of a basic setup for the connections, which includes functions like:
Now, the first piece of code, which is the Main Computer, is the one that actually works (Or so I've been led to believe, without the other two I can't test for continous use)
Next, we've got the Pocket Computer (defined as "phone" in Main Computer); this gives me the following error: bios:14: [string "startup"]:69: '=' expected
And finally, the house control computer which errors me with: bios:14 [string "startup"]:20: unexpected symbol
I feel frustrated over the fact that I can't seem to track down the error… even if it looks so simple. I checked the code throughoutly and it doesn't seem like I made any mistake; which is why I post this even if "=" expected is defined in the common errors list.
Thanks again in advance.
Here goes:
I'm trying to make a telecommunications network in between several computers (Three, so far), a pocket advanced computer, a main computer which acts like both a server and console, and finally a computer to control my house (Doors, lightning, etc.)
Mainly, my computers are composed of a basic setup for the connections, which includes functions like:
function sethost() --checks if rednet is started, if not, it errors. If it is, then it sets the computer on a host.
sethost_start = rednet.isOpen()
if sethost_start == true then
rednet.host("alpha", "main")
else error("rednet is not started")
end
hostset = true --Just an utility, I might remove it later on since so far I haven't used it.
end
function peerCheck() --Checks for the availability of the other computers, only the Main Computer has all of them, the others just need to access the Main Computer
homeControlComputer = rednet.lookup("beta", "homeControl") --The hierarchy is set as a level, the protocols go from the first level to upper levels, the first one being the root; I chose to use greek numerals in an ascending manner
storageControlComputer = rednet.lookup("beta", "storageControl") --Storage Control isn't available /yet/
phone = rednet.lookup("gamma", "pocketComputerDG")
end
function startup() --This runs every function, and determines every global variable in the order required. It's called right after being defined.
monitor = peripheral.wrap("bottom")
rednet.open("left")
sethost()
peerCheck()
end
Now, the first piece of code, which is the Main Computer, is the one that actually works (Or so I've been led to believe, without the other two I can't test for continous use)
function sethost()
sethost_start = rednet.isOpen()
if sethost_start == true then
rednet.host("alpha", "main")
else error("rednet is not started")
end
hostset = true
end
function peerCheck()
homeControlComputer = rednet.lookup("beta", "homeControl")
storageControlComputer = rednet.lookup("beta", "storageControl")
phone = rednet.lookup("gamma", "pocketComputerDG")
end
--action functions start
function homeControlComputer_door()
rednet.send(homeControlComputer, openMainGate_toggle)
local senderId, message, protocol = rednet.receive(beta, 20)
local message = doorState
term.blit(message, "blue", "black")
end
function homeControlComputer_lights()
rednet.send(homeControlComputer, turnLights_toggle)
local senderId, message, protocol = rednet.receive(beta, 20)
local message = lightsState
term.blit(message, "blue", "black")
end
--action functions end
function startup()
monitor = peripheral.wrap("bottom")
rednet.open("left")
sethost()
peerCheck()
end
startup()
while true do
senderId, message, protocol = rednet.receive()
if senderId == phone and protocol == gamma then
if message == "request_doorState" then
rednet.send(phone, doorState)
elseif message == "request_lightsState" then
rednet.send(phone, lightsState)
elseif message == "door" then
homeControlComputer_lights()
elseif message == "light" then
homeControlComputer_door()
end
end
end
Next, we've got the Pocket Computer (defined as "phone" in Main Computer); this gives me the following error: bios:14: [string "startup"]:69: '=' expected
--phone
function sethost()
sethost_start = rednet.isOpen()
if sethost_start == true then
rednet.host("gamma", "pocketComputerDG")
else error("rednet is not started")
end
hostset = true
end
function peerCheck()
mainComputer = rednet.lookup("alpha", "main")
end
function checkstates()
rednet.send(mainComputer, "request_doorStatus")
local senderId, message, protocol = rednet.receive(alpha, 20)
if message == true or false then
doorState = message
rednet.send(mainComputer, "request_lightsStatus")
local senderId, message, protocol = rednet.receive(alpha, 20)
if message == true or false then
lightsState = message
end
end
end
function startup()
pocketComputerDG_nativeMonitor = term.native()
mainBgcolor = colors.lightBlue
mainTextColor = colors.white
secondBgColor = colors.blue
secondTextColor = colors.lightGray
cords = {
mainWindowAlphaX = 8, mainWindowAlphaY = 0, mainWindowBetaX = 8, mainWindowBetaY = 20,
houseControlAlphaX = 19, houseControlAlphaY = 7, houseControlBetaX = 8, houseControlBetaY = 5,
doorOpenAlphaX = 19, doorOpenAlphaY = 7, doorOpenBetaX = 8, doorOpenBetaY = 5,
lightsOnAlphaX = 0, lightsOnAlphaY = 7, lightsOnBetaX = 8, lightsOnBetaY = 5
}
rednet.open("front")
sethost()
peerCheck()
pocketComputerDG_mainMenu()
checkstates()
end
--action functions start
function pocketComputerDG_mainMenu()
houseControlMenuActive = false
--Main Window
pocketComputerDG_nativeMonitor_windowInfo = window.create(pocketComputerDG_nativeMonitor, 8, 0, 8, 20, true)
term.redirect(pocketComputerDG_nativeMonitor_windowInfo)
term.blit("DiegoG's Touchpad, please select a function", mainTextColor, mainBgcolor)
--House Control
pocketComputerDG_nativeMonitor_windowHouseControl = window.create(pocketComputerDG_nativeMonitor, 19, 7, 8, 5, true)
term.redirect(pocketComputerDG_nativeMonitor_windowHouseControl)
term.blit("House Control", secondTextColor, secondBgColor)
end
function pocketComputerDG_houseControlMenu()
term.clear
houseControlMenuActive = true
pocketComputerDG_nativeMonitor_windowHouseControl_DoorOpen = window.create(pocketComputerDG_nativeMonitor, 19, 7, 8, 5, true)
term.redirect(pocketComputerDG_nativeMonitor_windowHouseControl_DoorOpen)
term.blit("Doors /n"..tostring(doorState), secondTextColor, secondBgColor)
pocketComputerDG_nativeMonitor_windowHouseControl_LightsOn = window.create(pocketComputerDG_nativeMonitor, 0, 7, 8, 5, true)
term.redirect(pocketComputerDG_nativeMonitor_windowHouseControl_LightsOn)
term.blit("Lights /n"..tostring(lightsState), secondTextColor, secondBgColor)
end
function messageMainComputer(msg)
rednet.send(mainComputer, msg)
local senderId, message, protocol = rednet.receive(alpha, 20)
end
--action functions end
startup()
while true do
mouseButton, mouseX, mouseY = os.pullEvent(mouse_click)
if mouseButton == 1 then
if mouseX >= cords.houseControlAlphaX and mouseX <= cords.houseControlBetaX then
if mouseY >= cords.houseControlAlphaY and mouseY <= cords.houseControlBetaY then
pocketComputerDG_houseControlMenu()
end
end
elseif houseControlMenuActive = true then
if mouseX >= cords.doorOpenAlphaX and mouseX <= cords.doorOpenBetaX then
if mouseY >= cords.doorOpenAlphaY and mouseX <= cords.doorOpenBetaY then
messageMainComputer("door")
end
elseif mouseX >= cords.lightsOnAlphaX and mouseX <= cords.lightsOnBetaX then
if mouseY >= cords.lightsOnAlphaY and mouseY <= cords.lightsOnBetaY then
messageMainComputer("light")
end
end
end
end
And finally, the house control computer which errors me with: bios:14 [string "startup"]:20: unexpected symbol
--houseControl
function sethost()
sethost_start = rednet.isOpen()
if sethost_start == true then
rednet.host("beta", "homeControl")
else error("rednet is not started")
end
hostset = true
end
function peerCheck()
mainComputer = rednet.lookup("alpha", "main")
end
--action functions start
function openMainGate()
local isDoorOpen = false
if isDoorOpen == false then redstone.setOutput("right", true) and isDoorOpen == true
elseif isDoorOpen = true then redstone.seOutput("right", false) and isDoorOpen == false
else error("isDoorOpen is neither true nor false") end
if isDoorOpen == true then
local doorState = "Door successfully opened."
elseif isDoorOpen == false then
local doorState = "Door successfully closed."
else error("doorState is neither true nor false") end
rednet.send("mainComputer", doorState)
end
function turnLights()
local areLightsOn = false
if areLightsOn == false then redstone.setOutput("left", true) and areLightsOn = true
elseif areLightsOn == true then redstone.setOutput("left", false) and areLightsOn = false
else error("areLightsOn is neither true nor false") end
if areLightsOn == true then
local lightState = "Lightning successfully turned on."
elseif areLightsOn == false then
local lightState = "Lightning successfully turned off."
else error("doorState is neither true nor false") end
rednet.send("mainComputer", lightState)
end
--action functions end
function startup()
rednet.open("front")
sethost()
peerCheck()
end
startup()
while true do
senderId, message, protocol = rednet.receive(alpha)
if
senderId = mainComputer and protocol = alpha
then
if message = openMainGate_toggle
then openMainGate()
elseif message = turnLights_toggle
then turnLights()
end
end
end
I feel frustrated over the fact that I can't seem to track down the error… even if it looks so simple. I checked the code throughoutly and it doesn't seem like I made any mistake; which is why I post this even if "=" expected is defined in the common errors list.
Thanks again in advance.