tables
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

tables

Started by pHaTTy, 12 January, 2004, 17:26:25

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pHaTTy

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*
Resistance is futile!

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


I like childish behavior. Maybe this post will be deleted next.

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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

pHaTTy

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,
Resistance is futile!

pHaTTy

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
Resistance is futile!

NightLitch

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
//NL

pHaTTy

/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 :)
Resistance is futile!

NotRabidWombat

#7
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.


I like childish behavior. Maybe this post will be deleted next.

plop

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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

pHaTTy

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 ;)
Resistance is futile!

NightLitch

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
//NL

tezlo

write(f, "{ ")
for i = 1, getn(table) do write(f, table..", ") end
write(f, " }\n")

NightLitch

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.
//NL

NightLitch

Would be nice if someone help me. getting nuts...

gonna sleep now.

/NL
//NL

NotRabidWombat

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


I like childish behavior. Maybe this post will be deleted next.

NightLitch

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.
//NL

NightLitch

#16
*DELETE, DOUBLE POST*
//NL

NightLitch

#17
*DELETE, DOUBLE POST*
//NL

NotRabidWombat

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


I like childish behavior. Maybe this post will be deleted next.

NightLitch

Thx Wombat. I got it working my way after some tries. Thx m8.

But have some mods til Am happy.

/NL
//NL

pHaTTy

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 :)))
Resistance is futile!

NotRabidWombat

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


I like childish behavior. Maybe this post will be deleted next.

pHaTTy

yep solved my mistake, thx alot tho :) now i know for sure i was doing it right ghehhe :)
Resistance is futile!

SMF spam blocked by CleanTalk