PtokaX forum

Development Section => Your Developing Problems => Topic started by: pHaTTy on 12 January, 2004, 17:26:25

Title: tables
Post by: pHaTTy on 12 January, 2004, 17:26:25
hi there, looking for some table genius;s

how can i do sopmething like this

      local s,e,name,command,cost,stylegain,label = strfind(line,"(%S+)|(%S+)|(%S+)|(%S+)|(%S+)")
      Weapons[name].name = name
      Weapons[name].command = command
      Weapons[name].cost = cost
      Weapons[name].stylegain = stylegain

if its poss??? please help me :D *hint hint*
Title:
Post by: NotRabidWombat on 12 January, 2004, 20:32:44
local s,e,name,command,cost,stylegain,label = strfind(line,"(%S+)|(%S+)|(%S+)|(%S+)|(%S+)")
Weapons[name] = {};
Weapons[name].name = name
Weapons[name].command = command
Weapons[name].cost = cost
Weapons[name].stylegain = stylegain

OR

local s,e,name,command,cost,stylegain,label = strfind(line,"(%S+)|(%S+)|(%S+)|(%S+)|(%S+)")
Weapons[name] = {["Name"] = name, ["Command"] = command, .... etc};

Why do you have a name index if it's what you use to access the table in the first place?

-NotRabidWombat
Title:
Post by: plop on 12 January, 2004, 20:50:22
QuoteOriginally posted by (uk-kingdom)pH?tt?
hi there, looking for some table genius;s

how can i do sopmething like this

      local s,e,name,command,cost,stylegain,label = strfind(line,"(%S+)|(%S+)|(%S+)|(%S+)|(%S+)")
      Weapons[name].name = name
      Weapons[name].command = command
      Weapons[name].cost = cost
      Weapons[name].stylegain = stylegain

if its poss??? please help me :D *hint hint*
1st change a bit 2 how you name and wanne call the vallue's, your making it really hard for yourself 2 get them out again.

TableOne[TableTwo[key]] = vallue
this should also work
TableOne[TableTwo] = {key=vallue, key2=vallue2, etc...
or
TableTwo = {key=vallue, key2=vallue2, etc...
TableOne[key] = TableTwo
the dot method only does 1 step, so TableOne.TableTwo.Name won't work.
but this works again.
TableOne[TableTwo.Name]

but if your lazy you can se multiple tables. lol
i'm playing with the same thing as you now on that goodfiles script. lol
for me this is also new, but sure is cool stuff.

plop
Title:
Post by: pHaTTy on 12 January, 2004, 20:52:52
QuoteOriginally posted by NotRabidWombat
local s,e,name,command,cost,stylegain,label = strfind(line,"(%S+)|(%S+)|(%S+)|(%S+)|(%S+)")
Weapons[name] = {};
Weapons[name].name = name
Weapons[name].command = command
Weapons[name].cost = cost
Weapons[name].stylegain = stylegain

OR

local s,e,name,command,cost,stylegain,label = strfind(line,"(%S+)|(%S+)|(%S+)|(%S+)|(%S+)")
Weapons[name] = {["Name"] = name, ["Command"] = command, .... etc};

Why do you have a name index if it's what you use to access the table in the first place?

-NotRabidWombat

hmm dunno i think its just for us dumb ppl lol

nah i never thought about it, its just so when i save em, i can save the call of .name instead of saving and parsing etc, hard to explain,, THANX alot second way is great, will get right on it :)))

phatty,
Title:
Post by: pHaTTy on 12 January, 2004, 20:53:40
QuoteOriginally posted by plop
QuoteOriginally posted by (uk-kingdom)pH?tt?
hi there, looking for some table genius;s

how can i do sopmething like this

      local s,e,name,command,cost,stylegain,label = strfind(line,"(%S+)|(%S+)|(%S+)|(%S+)|(%S+)")
      Weapons[name].name = name
      Weapons[name].command = command
      Weapons[name].cost = cost
      Weapons[name].stylegain = stylegain

if its poss??? please help me :D *hint hint*
1st change a bit 2 how you name and wanne call the vallue's, your making it really hard for yourself 2 get them out again.

TableOne[TableTwo[key]] = vallue
this should also work
TableOne[TableTwo] = {key=vallue, key2=vallue2, etc...
or
TableTwo = {key=vallue, key2=vallue2, etc...
TableOne[key] = TableTwo
the dot method only does 1 step, so TableOne.TableTwo.Name won't work.
but this works again.
TableOne[TableTwo.Name]

but if your lazy you can se multiple tables. lol
i'm playing with the same thing as you now on that goodfiles script. lol
for me this is also new, but sure is cool stuff.

plop

Hmm i think you lost me, with the errm all of it lol :S
Title:
Post by: NightLitch on 12 January, 2004, 21:00:11
How about making a HOW-TO later then Plop,Wombat or
someone with great experience.

Would want to learn some more about DoubleTables(my words now)
like this:

Table1 = {
                 Table2 = {}
                 Table3 = {}
               }

-------------------------------

Table1[Table2] = Value

is that the right way calling above Values/Tables ?

And Saving Say:

Table1[Table2] = SaveValue

is that correct to save to a file or Table1 then ??

Hope you get my point guys... as you all now my english sucks... ;-D
Title:
Post by: pHaTTy on 12 January, 2004, 21:06:04
/NightLitch

Creator of BattleCat , Soon to come here ...

When you think you got it, you don't,
Just keep trying in the right direction...

plop should be Moderator !!!

i agree with last line, and Rabid i reckon :)
Title:
Post by: NotRabidWombat on 12 January, 2004, 21:28:24
Creation is simple:
OuterTable = {
   ["InnerTable1"] = { ["data"] = 2 },
   ["InnerTable2"] = { ["notdata"] = 1, ["test"]  = 3 }
};
You have to think in terms of reference point. When you index into the outer table, you now have a reference to the inner tables and must access their data as if you were accessing a normal table.

OuterTable["InnerTable1"];
-- returns a table
OuterTable["InnerTable1"]["data"];
-- returns 2
OuterTable["data"] = 7;
-- adds another index to the outertable, does not affect other inner tables.
OuterTable["InnerTable1"]["test"] = 0;
-- adds another index to innertable1
OuterTable["InnerTable2"] = nil;
-- effectively deletes the InnerTable2 (the garbage collector will take care of the rest)

Unfortunetly, I only drop by here to check for new versions of PtokaX (feeling very discouraged). I do not have time to be a moderator again.

-NotRabidWombat

P.S. -
OuterTable["InnerTable1"]["data"];
OuterTable.InnerTable1["data"];
OuterTable.InnerTable1.data;

These statements all perform the same operation.
Title:
Post by: plop on 12 January, 2004, 21:34:46
QuoteOriginally posted by (uk-kingdom)pH?tt?
/NightLitch

plop should be Moderator !!!

i agree with last line, and Rabid i reckon :)
thx guy's

and phatty, that 1 wombat gave and 1 of the way's i told you is the easyests 2 start with (i think).
TableOne[TableTwo] = {key=vallue, key2=vallue2, etc...

but like they say there is more then 1 way 2 rome, use the 1 you think is the easyest.
thats why i gave all posible ways, also the part witch made you confused has to make you think. lol
i'm personaly gone try all the way's, i'm 2 cuorius (how the hell do you spell that word ?).
if phatty doesn't beat me 2 it i'll make a how-to when i get it all under controll.

plop
Title:
Post by: pHaTTy on 12 January, 2004, 21:55:24
QuoteOriginally posted by plop
QuoteOriginally posted by (uk-kingdom)pH?tt?
[code]
/NightLitch

plop should be Moderator !!!
[/code[

i agree with last line, and Rabid i reckon :)
thx guy's

and phatty, that 1 wombat gave and 1 of the way's i told you is the easyests 2 start with (i think).
TableOne[TableTwo] = {key=vallue, key2=vallue2, etc...

but like they say there is more then 1 way 2 rome, use the 1 you think is the easyest.
thats why i gave all posible ways, also the part witch made you confused has to make you think. lol
i'm personaly gone try all the way's, i'm 2 cuorius (how the hell do you spell that word ?).
if phatty doesn't beat me 2 it i'll make a how-to when i get it all under controll.

plop

No m8 its all yours :))

n thx, i will keep looking at thiese posts heheh :) try understand more and more :)

Curious ;)
Title:
Post by: NightLitch on 05 February, 2004, 22:13:11
Ok now, I wanna learn this propetly now.

this is Tezlo's short code:

Table = {
  ["somenick"] = { "someip", "sometime", "someinfo" },
}
function GetSomeInfo(user, nick)
  local tmp = table[nick]
  if tmp then
    user:SendData("somebot", "nick: "..nick.." ip: "..tmp[1])
  else -- there is no info on nick
    user:SendData("somebot", "no info for "..nick)
  end
end

I want from this learn:

how do I create the table ex:

Table[curUser.sName] = {ip,myinfostring,etc}

this saves in Serialize very strange so how do I do it.

Simple I wanna know how to save it so it looks like the code above.

/Thx / NL
Title:
Post by: tezlo on 05 February, 2004, 23:23:01
write(f, "{ ")
for i = 1, getn(table) do write(f, table..", ") end
write(f, " }\n")
Title:
Post by: NightLitch on 06 February, 2004, 00:47:24
plz Tezlo could you be so kind give me a complete function to study.

That lines don't say much for me, execpt I understand a little bit
what they do.

Tired to but wanna get it. plz.
Title:
Post by: NightLitch on 06 February, 2004, 01:01:02
Would be nice if someone help me. getting nuts...

gonna sleep now.

/NL
Title:
Post by: NotRabidWombat on 06 February, 2004, 02:23:35
From a while back.
tTestTable = { "this", "is", "a", "test",
{ [1] = "inner", [2] = "table", [3] = {"blah"}, ["test"] = "asdf", ["test2"] = 4, [12] = 12},
-12};

function Main()
local hFile = openfile("output.txt", "w");
Serialize(tTestTable, "tTestTable", hFile);
closefile(hFile);
end

function Serialize(tTable, sTableName, hFile, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(hFile, "hFile equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";

write(hFile, sTab..sTableName.." = {\n" );

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
write(hFile, sTab.."\t"..sKey.." = "..sValue);
end

write(hFile, ",\n");
end

write(hFile, sTab.."}");
end

-NotRabidWombat
Title:
Post by: NightLitch on 06 February, 2004, 15:27:46
Thx alot Wombat. But When I save in the file the outcome is:

tTestTable = {
["[GE]jocke"] = {
[1] = "127.0.0.1",
[3] = "$MyINFO $ALL [GE]jocke Description<++ V:0.306,M:A,H:2/0/0,S:9,O:3>$ $LAN(T3)$nightlitch@swenorth.myftp.org$80710313761$|",
},
}

I want it like this:

tTestTable = {
["[GE]jocke"] = {[1] = "127.0.0.1",[3] = "$MyINFO $ALL [GE]jocke Description<++ V:0.306,M:A,H:2/0/0,S:9,O:3>$ $LAN(T3)$nightlitch@swenorth.myftp.org$80710313761$|",},
}

And why is it skipping 2 I get 1 & 3. help plz.
Title:
Post by: NightLitch on 06 February, 2004, 15:31:32
*DELETE, DOUBLE POST*
Title:
Post by: NightLitch on 06 February, 2004, 15:35:17
*DELETE, DOUBLE POST*
Title:
Post by: NotRabidWombat on 06 February, 2004, 17:10:29
The first one is MUCH easier to read for someone that may want to modify the serialized data. If you don't like the way it saves change the function. You'll probably want to add another boolean variable to the argument list so you can control the endline in:

write(hFile, sTab..sTableName.." = {\n" );
write(hFile, ",\n");

You are missing 2 because it is nil or unset (same thing)

-NotRabidWombat
Title:
Post by: NightLitch on 06 February, 2004, 21:43:18
Thx Wombat. I got it working my way after some tries. Thx m8.

But have some mods til Am happy.

/NL
Title:
Post by: pHaTTy on 07 February, 2004, 00:42:18
well this is along the lins of tables so how can i do something like this, i just cant get anything to work

local s,e,rangenr,therest = strfind(line,"$(%S+)$(.*)")
local s,e,from,to = strfind(therest,"(%S+)|(%S+)")
Ranges = {
rangenr = {}
}
rangenr[from] = to

plzzz help :)))
Title:
Post by: NotRabidWombat on 07 February, 2004, 06:20:43
Ranges = {

[rangenr] = { [from] = to }

}

I think that's what you want to do. Not sure what you're trying to do though :-P

http://www.lua.org/manual/4.0/manual.html#4.5

4.5.7 is Table Constructors.

-NotRabidWombat
Title:
Post by: pHaTTy on 07 February, 2004, 10:33:19
yep solved my mistake, thx alot tho :) now i know for sure i was doing it right ghehhe :)