I'm trying to create a registration code for my email system that sends the label of the sending computer to a registration server as the variable regname. It also sends it's ID to the server as regid. Now, what I need the server to do is create a variable, except the variable's name needs to be the computer ID's number. I don't know how to create a new variable using the value of another. Any help here?
[LUA][Question]
Started by TCGM, Jul 06 2012 10:39 AM
7 replies to this topic
#1
Posted 06 July 2012 - 10:39 AM
#2
Posted 06 July 2012 - 12:02 PM
Hm probably either a global variable or one in a table
so like
or probably better
If that makes sense to you
so like
label = "abc" _G[label] = "bleh" print(_G["abc"])
or probably better
local labelList = {}
local label = "blah"
labelList[label]="abc"
print(labelList["blah"])
If that makes sense to you
#3
Posted 06 July 2012 - 01:10 PM
Sorry to sound like a noob, but I can just BARELY grasp what you typed. And it's not what I need unfortunately; I need to be able to have any computer on the network register with the main server, creating a brand new variable (the name of the computer as determined by sent label) and assigning it the numeric value of the ID the computer that sent it registers as (it appears that the server can see that natively, so disregard the regid send act). I guess you could say I'm trying to make a database, so instead of typing in IDs for the computer targets I can instead type the names, and have the main server look them up and then forward the message to the correct ID by comparing names against the database.
#4
Posted 06 July 2012 - 01:13 PM
Well I'm better at helping people who aren't newish xD
And well i just showed a way to use a variable to make another variable named after the former
And well i just showed a way to use a variable to make another variable named after the former
#5
Posted 06 July 2012 - 01:16 PM
Pinkishu, on 06 July 2012 - 01:13 PM, said:
Well I'm better at helping people who aren't newish xD
And well i just showed a way to use a variable to make another variable named after the former
And well i just showed a way to use a variable to make another variable named after the former
I know this creates the table. > local labelList = {}
I'm assuming this creates, inside said table, a variable called "label"? local label = "blah"
What is this? > labelList[label]="abc"
I know this prints it, which is nice.. But I don't really need printback atm. print(labelList["blah"])
#6
Posted 06 July 2012 - 01:22 PM
well syntax
table[key] = value
sets the key in table to value
so you have a table which is empty
now it sets the key in this case label which has "blah" as its value (so labelList[label] is the same as doing labelList["blah"] now) to value
so labelList[label]="abc" makes the table:
{
blah="abc"
}
table[key] = value
sets the key in table to value
so you have a table which is empty
now it sets the key in this case label which has "blah" as its value (so labelList[label] is the same as doing labelList["blah"] now) to value
so labelList[label]="abc" makes the table:
{
blah="abc"
}
#7
Posted 06 July 2012 - 01:37 PM
Pinkishu, on 06 July 2012 - 01:22 PM, said:
well syntax
table[key] = value
sets the key in table to value
so you have a table which is empty
now it sets the key in this case label which has "blah" as its value (so labelList[label] is the same as doing labelList["blah"] now) to value
so labelList[label]="abc" makes the table:
{
blah="abc"
}
table[key] = value
sets the key in table to value
so you have a table which is empty
now it sets the key in this case label which has "blah" as its value (so labelList[label] is the same as doing labelList["blah"] now) to value
so labelList[label]="abc" makes the table:
{
blah="abc"
}
#8
Posted 06 July 2012 - 03:05 PM
You can save it to a file, using the fs api.
If you want to save the whole table, you can serialize it.
If you want to save the whole table, you can serialize it.
local list = {}
-- add something to the list
-- and now save it:
local file = fs.open("path to the save file", "w") -- open the file
if file then -- check if it's open
local s = textutils.serialize(list) -- serialize the table, so we have a string to save to the file
file.write(s) -- write it to the file
file.close() -- always close the file handles
end
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











