|
| | #1 (permalink) |
| UWSVN Contributor ![]() ![]() ![]() Join Date: Dec 2007 Location: Hamburg, Germany
Posts: 230
![]() | (I hope nobody really mind about this not being wiremod lua )I got a small problem with some Table-Handling code. To better explain my problem, I created a small part of code: Code: function TestTables()
local buffer = {}
for i = 5,19 do
buffer[i] = math.random(-20,20)
Msg("Write "..buffer[i].." at position "..i.."\n")
end
Msg("Table contains now "..#buffer.." Entries\n")
Msg("Those are:\n")
for key,val in ipairs(buffer) do
Msg("Key: "..key.. " Value: "..val.."\n")
end
end
concommand.Add("TestTables",TestTables)
Code: ] TestTables Write 14 at position 5 Write 18 at position 6 Write 18 at position 7 Write 15 at position 8 Write 12 at position 9 Write -7 at position 10 Write -16 at position 11 Write -19 at position 12 Write 11 at position 13 Write 0 at position 14 Write -4 at position 15 Write 10 at position 16 Write 12 at position 17 Write -3 at position 18 Write 9 at position 19 Table contains now 19 Entries Those are: What is up?!
__________________ cmao = coding my ass off Free Fall Extension: 20081213 0002 Wire Socket Radio Rev2: 20081021 0932 (And it WORKS! (Mostly)) Please take a look into the Free Fall Extension and leave at least a small comment please, because it makes me kinda feel bad, if i put work into something, that nobody cares about. Understandable, isn't it? ![]() My IQ is 139 ![]() |
| | |
| Sponsored Links | |
| | #2 (permalink) |
| Advanced Member ![]() | Both # and ipairs expect the table to start at 1.
__________________ Wire developer. Currently working at: Topaz (A scripting language written in Lua) <Fox682> itsbot: follow the white rabbit <ITSBOT> i don't want to follow that. Last edited by itsbth; 08-07-2008 at 10:55 AM.. Reason: Changed wording |
| | |
| | #3 (permalink) |
| UWSVN Contributor ![]() ![]() ![]() Join Date: Dec 2007 Location: Hamburg, Germany
Posts: 230
![]() | How do i get the count of entries in a table then? But the "Pairs" thing works better, yea. But i have one question: If i delete one entry in the table, the "for" command cycles through; what will it do? cycling through the left entries?
__________________ cmao = coding my ass off Free Fall Extension: 20081213 0002 Wire Socket Radio Rev2: 20081021 0932 (And it WORKS! (Mostly)) Please take a look into the Free Fall Extension and leave at least a small comment please, because it makes me kinda feel bad, if i put work into something, that nobody cares about. Understandable, isn't it? ![]() My IQ is 139 ![]() |
| | |
| | #4 (permalink) |
| Advanced Member ![]() | #1 Why don't you start your tables at one? #2 Just try it yourself and see what happens.
__________________ Wire developer. Currently working at: Topaz (A scripting language written in Lua) <Fox682> itsbot: follow the white rabbit <ITSBOT> i don't want to follow that. |
| | |
| | #5 (permalink) |
| UWSVN Contributor ![]() ![]() ![]() Join Date: Dec 2007 Location: Hamburg, Germany
Posts: 230
![]() | Why I don't start at one? That is easy to explain. I want to have this for a transmitting wire thingy (Yes, my WSR). When values in some cells (Hi-Speed of course) change, the change has to be send. So I write that change into a change buffer. Then the Key is the cell-Address and the value is the value of the change. I need to start wherever I want in the Table, to make it possible, to send single values in the right positions, and not the whole memory at once (, what could be a problem with 65565 cells, right? )PS: Using an extra-counter variable and the "pairs" command instead of "ipairs" it magicly works. I'ma give some debug-outputs: Code: WriteCell called WriteCell 16 Writing 444.5020905179 To the buffer at 16 Buffer contains now 1 entries WriteCell called WriteCell 17 Writing 344.9507126072 To the buffer at 17 Buffer contains now 2 entries WriteCell called WriteCell 18 Writing 61.06753746147 To the buffer at 18 Buffer contains now 3 entries WriteCell called WriteCell 19 Writing 935.23972289193 To the buffer at 19 Buffer contains now 4 entries WriteCell called WriteCell 20 Writing 920.43824579608 To the buffer at 20 Buffer contains now 5 entries WriteCell called WriteCell 21 Writing 615.98559526353 To the buffer at 21 Buffer contains now 6 entries WriteCell called WriteCell 22 Writing 653.43180639058 To the buffer at 22 Buffer contains now 7 entries WriteCell called WriteCell 23 Creating Message Max Size: 512 Key: 19 Val: 935.23972289193 Additional: 19,1,935.23972289193 New Size: 38 Key: 16 Val: 444.5020905179 Additional: ,16,1,444.5020905179 New Size: 58 Key: 20 Val: 920.43824579608 Additional: ,20,1,920.43824579608 New Size: 79 Key: 17 Val: 344.9507126072 Additional: ,17,1,344.9507126072 New Size: 99 Key: 21 Val: 615.98559526353 Additional: ,21,1,615.98559526353 New Size: 120 Key: 18 Val: 61.06753746147 Additional: ,18,1,61.06753746147 New Size: 140 Key: 22 Val: 653.43180639058 Additional: ,22,1,653.43180639058 New Size: 161 HiMsg:49:ShareRAM:19,1,935.23972289193,16,1,444.5020905179,20,1,920.43824579608,17,1,344.9507126072,21,1,615.98559526353,18,1,61.06753746147,22,1,653.43180639058 ---------------------- OwnPort: 27201 Message: HiMsg:49:ShareRAM:19,1,935.23972289193,16,1,444.5020905179,20,1,920.43824579608,17,1,344.9507126072,21,1,615.98559526353,18,1,61.06753746147,22,1,653.43180639058 msgType: HiMsg Message: HiMsg:49:ShareRAM:19,1,935.23972289193,16,1,444.5020905179,20,1,920.43824579608,17,1,344.9507126072,21,1,615.98559526353,18,1,61.06753746147,22,1,653.43180639058 msgType: HiMsg msgNum: 49 lastReceivedMsgNum: 48 msgDataType: ShareRAM ---------------------- OwnPort: 27200 Message: HiNull msgType: HiNull ![]() PSS: Thx for help though
__________________ cmao = coding my ass off Free Fall Extension: 20081213 0002 Wire Socket Radio Rev2: 20081021 0932 (And it WORKS! (Mostly)) Please take a look into the Free Fall Extension and leave at least a small comment please, because it makes me kinda feel bad, if i put work into something, that nobody cares about. Understandable, isn't it? ![]() My IQ is 139 ![]() Last edited by Free Fall; 08-08-2008 at 07:49 AM.. |
| | |
| Sponsored Links | |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|