list of strings?
#1
Posted 29 March 2015 - 12:46 AM
#2
Posted 29 March 2015 - 01:12 AM
#3
Posted 29 March 2015 - 01:42 AM
You want to store data, using a table, but don't know how, and thought of using fs to do it.
-fs is for saving things permanently. It's good not good to use it to store temporary variables.
You are trying to debug your code
First of all, here's a tutorial on tables
Second of all, to check if a line of code ran, the best you can do is:
myFunction() print("Ran.")
Edited by Geforce Fan, 29 March 2015 - 01:44 AM.
#4
Posted 29 March 2015 - 01:56 AM
Enderchest <list>/<add>/<remove>
list would list out all of the color combinations i have, add would allow me to add a used combination, and remove would allow me to remove a combination, and i would want my combinations stored such that they can be backed up via floppy disk.
Also, for checking if a line of code ran, i didn't mean debugging, i want to return the value of a print() command, and then have
if printWasTrueOrFalse == true then
print("true")
else
print("false")
Edited by YUGATUG, 29 March 2015 - 01:57 AM.
#5
Posted 29 March 2015 - 02:59 AM
file.write(textutils.serialize(table))
To get that file, open it, and do
table = textutils.unserialize(file.readAll())
Why do you need to return the value of a print command?
Edited by Geforce Fan, 29 March 2015 - 02:59 AM.
#6
Posted 29 March 2015 - 05:27 AM
Geforce Fan, on 29 March 2015 - 02:59 AM, said:
Don't do that EXACTLY, you'd override the table API
YUGATUG, on 29 March 2015 - 01:56 AM, said:
Well, you can check if a function errors with pcall:
local state,err = pcall(print,"hi")
If the function does error, state will be false and err will be the error. Otherwise, state will be true and err will be nil
You shouldn't need to check individual functions, just put your code into one huge function, then pcall that
#7
Posted 29 March 2015 - 03:55 PM
#8
Posted 29 March 2015 - 04:14 PM
#9
Posted 29 March 2015 - 04:19 PM
If i don't do that, what should i do? I'd of course change the variable name, but if that command overwrites the table API, what wouldn't?
#10
Posted 29 March 2015 - 05:32 PM
YUGATUG, on 29 March 2015 - 03:55 PM, said:
Instead of looking at what 'print' returns, you could check how many entries are in the table that stores the colors, and if there aren't any then do the print("Error: No entries")
YUGATUG, on 29 March 2015 - 04:19 PM, said:
If i don't do that, what should i do? I'd of course change the variable name, but if that command overwrites the table API, what wouldn't?
Just don't use 'table' as a variable and you'll be fine
#11
Posted 29 March 2015 - 06:02 PM
Btw i subbed to your channel
#13
Posted 29 March 2015 - 07:47 PM
Geforce Fan, on 29 March 2015 - 02:59 AM, said:
file.write(textutils.serialize(table))
To get that file, open it, and do
table = textutils.unserialize(file.readAll())
Why do you need to return the value of a print command?
I made a program called test:
table = {"yolo"}
file.write(textutils.serialize(table))
table = textutils.unserialize(file.readAll())
then i got this error: "test:2: attempt to index? (a nil value)"
then if i try to run ANY command in the shell it gives me this error: "list:21: attempt to call nil" and i have to reboot to use the computer again.
Edited by YUGATUG, 29 March 2015 - 07:48 PM.
#14
Posted 29 March 2015 - 07:51 PM
Okay, I asumed basic knowledge on fs, sorry.
Here's what you should do
_table = {"yolo"}--#Define global '_table' as {"yolo"} file = fs.open("Insertfilenamehere","w")--#change Insertfilenamehere to your filename, "w" means that it's being opened in write mode file.write(textutils.serialize(_table))--#Write the table to the file file.close()--#Close the file. THIS IS ABSOLUTELY NECESSARY! To open: file = fs.open("Insertfilenamehere","r") --#change Insertfilenamehere to your filename, "r" means that it's being opened in read mode _table = textutils.unserialize(file.readAll()) --#Assign global '_table' to the table in that file file.close()--#Close the file. THIS IS ABSOLUTELY NECESSARY!
Edited by Geforce Fan, 29 March 2015 - 07:55 PM.
#15
Posted 29 March 2015 - 08:01 PM
#16
Posted 29 March 2015 - 08:09 PM
print( textutils.serialize( _table ) )
Just use this after loading the table from the file and it should work fine.
#17
Posted 29 March 2015 - 10:17 PM
{
"yolo",
}
instead of:
yolo
#18
Posted 29 March 2015 - 10:19 PM
print( _table[ 1 ] )
#19
Posted 29 March 2015 - 11:10 PM
No matter what i put after test, the program still outputs
{
"yolo",
}
even though the yolo in enderList is changed to whatever i put after test.
KingofGamesYami, on 29 March 2015 - 10:19 PM, said:
print( _table[ 1 ] )
#20
Posted 29 March 2015 - 11:35 PM
YUGATUG, on 29 March 2015 - 11:10 PM, said:
No, you're changing "enderay", not "enderList". Remember that global variables you define don't have their contents wiped until the whole computer reboots.
YUGATUG, on 29 March 2015 - 11:10 PM, said:
So use _table[1], _table[2], etc... or iterate through them... or use specific key-names... whatever. Here, have another tutorial.
Edited by Bomb Bloke, 29 March 2015 - 11:36 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users