This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Live
PTR
10.2.7
PTR
10.2.6
Beta
[Scripting] Table problem
Post Reply
Return to board index
Post by
Wildhorn
I'll skip the useless code, so here is the direct problem:
Test1.Test2.Test3.Test5 = 100
print (Test1.Test2.Test3.Test5)
print(#Test1.Test2.Test3)
How the &*!@ the first print can return 100, if the second print return 0.
How can I have something in "Test1.Test2.Test3.Test5" if "Test1.Test2.Test3" return me that I have 0 entry?
I just dont get it. There need to be something in "Test1.Test2.Test3" to have something in "Test1.Test2.Test3.Test5", no?
It is pretty late and my brain want to explode from all the table stuff I did the whole night. Did I miss something or what?
EDIT: I think I figured the problem, but I still dont understand why it does that. It seems # doesnt count tables unless they have been specifically been designated to a position via Test.
In my example, the table was made via Test1 = {Test2 = {Test3 = {}}}, which seem to @#$% up "#".
EDIT2: I found the *!@# of my problem, but it doesnt fix it >_<
/run local Test1 = {} Test1 = {} print(#Test1) -- print 1
/run local Test1 = {Test2 = {}} print(#Test1) -- print 0
/run local Test1 = {{}} print(#Test1) -- print 1
So, why the hell giving a name to the first "entry" of Test1 in example2 prevent "#" to count it?
I need a way to make 2nd line to count correctly, else I am !@#$ed up and will have to rescript over 500 lines of code >_<
Post by
Wanderingfox
what... exactly, are you doing? It's kind of hard to follow what you're looking for exactly...
As for why the # operator does not work on your second example... # only works on indexed tables. It does not work on non-sequential tables (ie. # returns the highest index in the table. If you use named key/value pairs, it will not work).
Post by
Wildhorn
Then how can I scan in a loop my table if all my key are named?
Post by
HighFive
The pairs iterator. Duh.
Post by
Wildhorn
The pairs iterator. Duh.
self
Sometimes I would punch myself in the face >_<
Post by
HighFive
self
Haha, that's a good one.
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.