This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
xblainx's profile picture

Help with status input variables

Started by xblainx, 23 December 2015 - 11:34 PM
xblainx #1
Posted 24 December 2015 - 12:34 AM
So i'm trying to make a monitor in my main base where it will ask the computer user questions on if certain things are yes or no, then change the text after about 3 questions that are similar and display text for other users to see when they log in. Here is the code i came up with, but if somebody could take a look and clean up. I also get the error : string 26, '=' is expected.

Thanks.

http://pastebin.com/F3vwkbYB

--Welcome to test
--local vars
local side = "left"--CHANGE THIS TO MONITOR SIDE

intro()


--FUNCTIONS

--Intro and program
function intro()
term.clear()
  term.setCursorPos(1,1)
  term.write("Welcome to Status Message")
  askc()
  sleep(1)
  askq()
  sleep(1)
  status()
  end

--Cart Status
function askc()
  term.clear()
  term.setCursorPos(1,1)_
  term.write("Is the cart running?")
  cart = read()
  if cart == "yes" then
    local scart = "Cart: Mining"
  else
    local scart = "Cart: OFF"
  end
end

--Quarry Status
function askq()
  term.clear()
  term.setCursorPos(1,1)
  term.write("Is the Quarry on?")
  quarry = read()
  if quarry == "yes" then
    local squarry = "Quarry: ON"
  else
    local squarry = "Quary: OFF"
  end
end

--Status Begin
function status()
mon = peripheral.wrap(side)
mon.clear()
mon.setTextSize(2)
mon.setCursorPos(1,1)
mon.write(scart)
mon.write(squarry)
mon.write(sneed)
end
Bomb Bloke #2
Posted 24 December 2015 - 01:31 AM
I also get the error : string 26, '=' is expected.

That extra _ you've got on line 25 counts as a variable name. It's guessing you were going to assign something to it, but instead the next line is following on immediately with a function call.
xblainx #3
Posted 24 December 2015 - 02:42 AM
I also get the error : string 26, '=' is expected.

That extra _ you've got on line 25 counts as a variable name. It's guessing you were going to assign something to it, but instead the next line is following on immediately with a function call.

Thanks, but i corrected it and now im receiving an error saying "test:5: attempt to call nil"

I basically just want the program to ask a couple of questions to make the program "user-friendly" (to avoid having the change the text every time)
and following the asking of the questions it displays on the monitor things like
"Quarry: ON
Cart: Active
Need: Diamond, get mining"'

Should'nt be too hard to make the program, but i made i by hand and im still pretty new to ComputerCraft. Thanks for helping again.
KingofGamesYami #4
Posted 24 December 2015 - 03:39 AM
You can't call a function before declaring it. On line 5 you call a non-existent function intro(). Move that line to the bottom of your script.
xblainx #5
Posted 24 December 2015 - 04:07 AM
You can't call a function before declaring it. On line 5 you call a non-existent function intro(). Move that line to the bottom of your script.
Thanks,

I have seem so now set local variables inside of the functions and at the bottom under the status function, im calling local variables that were defined in previous functions. How can i get around this and read out the local functions that are set inside of functions: askc(), askq(), and askn()
Bomb Bloke #6
Posted 24 December 2015 - 04:21 AM
Either have those functions return those values, or pre-declare the variables as local before you define the functions that make use of them.