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

Tables and things

Started by buttars, 03 April 2015 - 02:10 PM
buttars #1
Posted 03 April 2015 - 04:10 PM
So I want to be able to write to a table, like adding an account with a balance, but I have searched the internet and haven't found much but of things that want to explain what tables are and how they are different in lua. Also I would like to know if it's possible to edit a global var in a different program on the same computer? If so could someone leave an example?


function bankBanner()
term.clear()
term.setCursorPos(1,3)
print("==================================================")
term.setCursorPos(13, 3)
print("Buttars' bank of Nigeria")
term.setCursorPos(1,13)
print("==================================================")
end
bankBanner()

function createAccount()
end

account = {
{name = "Buttars", password = "1590", balance = 9000}

}
KingofGamesYami #2
Posted 03 April 2015 - 05:24 PM
Yes, you can edit globally defined variables with programs - however if the other script defines it on run, it'll be set to that value.

For instance,

account = {name="hello"}

Then another program:


print( account.name )

———————

As for tables, you probably want to know how to save/load a table. textutils.serialize turns a table into a string, which can then be written to a file.
HPWebcamAble #3
Posted 04 April 2015 - 01:01 AM
I have searched the internet and haven't found much but of things that want to explain what tables are and how they are different in lua

What did you search???

Doesn't matter, here's a good explanation of tables:
http://lua-users.org/wiki/TablesTutorial
KRHN #4
Posted 04 April 2015 - 07:04 AM
It is not good idea because your variables can remove from computer on server restart or you shutdown computer.My prefer save variables into a program like "accounts". You can do this with FS API http://computercraft.info/wiki/Fs_%28API%29

You can make your serialize system but it is hard for beginners. You can serialize when save and unserialize when load your accounts with they;
http://computercraft.info/wiki/Textutils.serialize
http://computercraft.info/wiki/Textutils.unserialize