Posted 14 August 2013 - 04:42 AM
Introduction
In Computer craft and lua in general there is a way of storing more than one data type in one variable. For example:
This declares a table but you can replace "myTable" with any name you want
To be able to store values in a table you need to use an index:
The first line of code is making a table called myTable and adding two variables inside "test" and "num" then the two print commands print out the value of myTable[test]and myTable[num]
To add/read variables from a table you type
or to receive
That's it for now but more chapters will be coming later click the link to see how to use tables with rednet to send nultiple messages in one ! "http://www.computerc...c/14743-relays/</index>
Examples
Example #1, storing and retrieving passwords
Troubleshooting
I don't understand!
In this case please post bellow the issue you are having and I will try to help you
It's giving me an error!
If this happens do the following:
In Computer craft and lua in general there is a way of storing more than one data type in one variable. For example:
local myTable = {}
This declares a table but you can replace "myTable" with any name you want
To be able to store values in a table you need to use an index:
local myTable = {test="lol",num=3}
print(myTable["test"])
print(tonumber(myTable["num"]))
The first line of code is making a table called myTable and adding two variables inside "test" and "num" then the two print commands print out the value of myTable[test]and myTable[num]
To add/read variables from a table you type
myTable[<index name="">] = "value to be stored"
or to receive
print(myTable["index of value to be retrieved "])
That's it for now but more chapters will be coming later click the link to see how to use tables with rednet to send nultiple messages in one ! "http://www.computerc...c/14743-relays/</index>
Examples
Example #1, storing and retrieving passwords
Spoiler
local passwords = {}
function main()
term.clear()
term.setCursorPos(1,1)
print("Enter new user:")
userNew = read()
print("Enter password: ")
passNew = read("x")
passwords[userNew] = passNew
print("Do you want to view users? y/n")
ans = read()
if ans == "y" then
term.clear()
term.setCursorPos(1,1)
print("Enter user: ")
userFind = read()
print("Password for user '"userFind"' is '"..passwords[userFind]"'")
read()
end
end
while true do
main()
end
Troubleshooting
I don't understand!
In this case please post bellow the issue you are having and I will try to help you
It's giving me an error!
If this happens do the following:
- *Create a reply to this topic
*In the reply add the code you are using and the error that is being generated