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

[Question] How i call a var by read() and print the var

Started by rickydaan, 16 March 2012 - 11:13 AM
rickydaan #1
Posted 16 March 2012 - 12:13 PM
So like:

a = "to"
b = "far"
c = "lands"

write("A, b or c ")
toPrint = read()
print(toPrint)


Thx for the help if someone helps
Espen #2
Posted 16 March 2012 - 12:44 PM
There are several ways to do this, for example:

Spoiler

local a = "to"
local b = "far"
local c = "lands"

write("A, b or c ")
local toPrint = read()
if string.lower(toPrint) == "a" then print( a )
if string.lower(toPrint) == "b" then print( b )
if string.lower(toPrint) == "c" then print( c )
… or …
Spoiler

local tToPrint = {}
tToPrint.a = "to"
tToPrint.b = "far"
tToPrint.c = "lands"

write("A, b or c ")
local input = read()
print(tToPrint[input])

But I'd suggest you start with some tutorials in this section: http://www.computerc...m/13-tutorials/
Also I'd recommend trying this program, which is kind of an interactive learning tutorial for CC that you can use ingame: http://www.computerc...torial-in-game/
rickydaan #3
Posted 16 March 2012 - 03:09 PM
Thx, but i dont need a tutorial, this was one of the small things i dont know, as im making a secret program… I think its going to be like 1000 - 5000 lines :D/>/>
rickydaan #4
Posted 16 March 2012 - 03:16 PM
And cant it be compacter; I got like 64 variables… And they need to be editable by some commands
Sebra #5
Posted 17 March 2012 - 05:48 AM
Second example is compact enough for you. You need tutorial to understand.
rickydaan #6
Posted 17 March 2012 - 09:25 AM
lol i saw the second one later lol, srry