Jump to content




Help with status input variables

help peripheral lua

5 replies to this topic

#1 xblainx

  • Members
  • 3 posts

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


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 24 December 2015 - 01:31 AM

View Postxblainx, on 24 December 2015 - 12:34 AM, said:

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.

#3 xblainx

  • Members
  • 3 posts

Posted 24 December 2015 - 02:42 AM

View PostBomb Bloke, on 24 December 2015 - 01:31 AM, said:

View Postxblainx, on 24 December 2015 - 12:34 AM, said:

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.

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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.

#5 xblainx

  • Members
  • 3 posts

Posted 24 December 2015 - 04:07 AM

View PostKingofGamesYami, on 24 December 2015 - 03:39 AM, said:

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()

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users