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

Variable for code?

Started by vyse, 10 October 2014 - 12:23 AM
vyse #1
Posted 10 October 2014 - 02:23 AM
I was trying to shorten things that i have to repeat for exp term.setCursorPos(1,1)
and i wanted to do x = term.setCursorPos(1,1)
then have it so when i needed to use that code all i needed to do was do function(X) or print(x)

but all i get is named expected. or the code as text.

So im wondering if you actually your variables for codes?

I know you can do like..

x = colors.red
y = 3

term.setBackground(x)
term.clear()
term.setCursorPos(10,1)
  print("hello")
sleep(y)
but can you do the whole thing?
KingofGamesYami #2
Posted 10 October 2014 - 02:29 AM
I think you are looking for functions.

local function x()
  term.setBackgroundColor( colors.red )
  term.clear()
  term.setCursorPos( 10, 1 )
  print( "hello" )
  sleep( 3 )
end
--#and calling it
x()
vyse #3
Posted 10 October 2014 - 02:59 AM
thank you