[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Problem accessing tables
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Problem accessing tables

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


Posted by Orogan   (23 posts)  [Biography] bio
Date Wed 28 Apr 2010 06:48 PM (UTC)

Amended on Wed 28 Apr 2010 06:57 PM (UTC) by Orogan

Message
Hello,

Can't seem to find answer to this:

I got a table wich looks like this


"Mobs":
  1:
    "room"="room&"
    "name"="mob1"
  2:
    "room"="room2"
    "name"="mob2"
  ...


I wanna print all mobnames but something like:


        
  mobnumber = table.maxn (Mobs)
  for v = 0, mobnumber, 1 do
  Note (Mobs[v].name)
  end



It wont replace the v value for the number.
What would be a correct way to do this?
Thanks for any help.

Orogan

edit: hehe as I post here I found the solution.

Problem was the table start from 1 not from zero, so should be

for v = 1, mobnumber, 1 do
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Wed 28 Apr 2010 06:50 PM (UTC)
Message
for i,name in ipairs(Mobs) do
  Note(name)


Note that Lua arrays start from 1, not 0, so your for loop would also need to start from 1.

Also, it would be helpful to show the error message or bad behavior you're seeing, so that we can confirm what your problem is (I suspect it's the off-by-one indexing but am not sure).

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] 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.


2,917 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]