Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Nested Tables

Nested Tables

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Jackson   (2 posts)  Bio
Date Tue 18 Nov 2014 09:05 PM (UTC)
Message
So Im capturing the room description and i read through the two threads from nick on lua tables but I dont understand how to edit the styles that I have saved to a table. I didnt see much on nested tables. cause all I have figured out just shows me another table.

table: 030CBFD0 1

So I saved the room

line, wildcards, styles = wait.match ("*")

Then I insert it into the table

table.instert(room, styles)


but now I want to be able to go through the tables and say edit the text or the textcolor in the nested tables. And I dont know how to do that. Say I want to go through the text and remove everything inside a [] and add a - to the start of each line. how is that done. Or Say I want to look at the text from key 23. Thanks


<aliases>
  <alias
   match="test2"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"
require "tprint"



wait.make (function ()

local room = {}

Send ("Look")

local w = wait.match ("[ Exits: n e s w u d ]")

while true do

line, wildcards, styles = wait.match("*")

if not string.match (line, "[A-Za-z0-9]") then

break 


end


table.insert (room, styles)

end  -- end loop

tprint(room)

end)</send>
  </alias>
</aliases>
Top

Posted by Jackson   (2 posts)  Bio
Date Reply #1 on Wed 19 Nov 2014 01:27 AM (UTC)
Message
So I figured out my answer, though im not exactly sure what the difference is in the for loops

for i goes through the Keys, but then what does for _ go and do?



for i, styles in ipairs (room) do
 
for _, style in ipairs (styles) do

style.text = style.text:gsub("%s%s+", " ")

print(style.text)
Top

Posted by Fiendish   USA  (2,558 posts)  Bio   Global Moderator
Date Reply #2 on Wed 19 Nov 2014 05:20 AM (UTC)

Amended on Wed 19 Nov 2014 05:27 AM (UTC) by Fiendish

Message
ipairs gives a loop over two things together: index number and value at that index.

In your first loop, i is assigned the index number, and styles is assigned the value (in this case another table) at that index.

_ is the conventional way of saying "I don't care about this one so I'll give it a name that I won't ever want to use like a single underscore."

https://github.com/fiendish/aardwolfclientpackage
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,958 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.