115 posts
Posted 15 May 2013 - 05:50 AM
Hello! Elg here again ;)/>
I am trying, as the title says, to read a tables contents from another file!
this is the main code
http://pastebin.com/44WMZwryand this is the table im trying to read
http://pastebin.com/R0DrG1f8This is using the immibis core mod, using the mag card system, but i dont believe that changes the code im looking for any!
I want to use the table from the file, as data for an if statement!
Any help is extremely appreciated, as always!
199 posts
Location
Switzerland
Posted 15 May 2013 - 07:31 AM
Hi Elgriton,
The txtfile has to be altered to look like this, so remove the "passs =" stuff
{"XTF93hlQV+sf9x4aB0GOtA==","56u2g+nWTUjFsB4AFM7Lg=="}
local function loadTable(str) -- create a function where str is path and filename for the password file
local h = fs.open(tostring(str), "r") -- opens the file in read mode
local nstr = h.readAll() -- reads the content to a string
local newtable = textutils.unserialize(nstr) -- converts the string to a table
return newtable -- returns the table
end
passs = loadTable("pass.txt") -- use the new function to assign the table to a variable
for i =1,#passtable do -- this is just a loop to show the passwords
print(passs[i]) -- you can access the password by index
end
Greets Loki
115 posts
Posted 15 May 2013 - 08:25 AM
Hi Elgriton,
The txtfile has to be altered to look like this, so remove the "passs =" stuff
{"XTF93hlQV+sf9x4aB0GOtA==","56u2g+nWTUjFsB4AFM7Lg=="}
local function loadTable(str) -- create a function where str is path and filename for the password file
local h = fs.open(tostring(str), "r") -- opens the file in read mode
local nstr = h.readAll() -- reads the content to a string
local newtable = textutils.unserialize(nstr) -- converts the string to a table
return newtable -- returns the table
end
passs = loadTable("pass.txt") -- use the new function to assign the table to a variable
for i =1,#passtable do -- this is just a loop to show the passwords
print(passs[i]) -- you can access the password by index
end
Greets Loki
This confuses me a bit, I dont get any errors when i run it, and when i print the passwords it works fine, but i cant use them in an iff statement, meaning
if pass == "whatever" then
print("works?")
else
print("no works:(")
end
replacing "whatever" with whatever you want to compare in the table
199 posts
Location
Switzerland
Posted 15 May 2013 - 08:39 AM
you need to use pass[1] or pass[2] cause the table u where giving here has 2 values
1 = XTF93hlQV+sf9x4aB0GOtA==
2 = 56u2g+nWTUjFsB4AFM7Lg==
115 posts
Posted 15 May 2013 - 08:40 AM
you need to use pass[1] or pass[2] cause the table u where giving here has 2 values
1 = XTF93hlQV+sf9x4aB0GOtA==
2 = 56u2g+nWTUjFsB4AFM7Lg==
You are such a life saver!! thank you my friend! :)/>
199 posts
Location
Switzerland
Posted 15 May 2013 - 08:57 AM
Thank you buddy, thats what we are here for, helping each other :)/>