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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Area List

Area List

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


Pages: 1 2  

Posted by VBMeireles   Brazil  (47 posts)  [Biography] bio
Date Fri 18 Mar 2016 02:46 PM (UTC)

Amended on Fri 18 Mar 2016 08:48 PM (UTC) by Nick Gammon

Message
I'm trying to setup an internal area list for manipulation through scripting and posterior importing/exporting to a "physical" database.

I have a very small programming background, but I've been slowly beginning to do experiment with Lua and I've come up with the following (it's in my plugin file's script CDATA) in order to implement such a list:

area_list = {
  area = {
    name,
    age_range = {
      min,
      max
    },
    coordinates = {
      x,
      y
    },
    monster_list = {},
    task_list = {}
  }
}

function fn_area_list()
  i = 1
  while area_list[i] do
    Note(area_list[i]["name"])
    i = i + 1
  end
end


It gives me no loading errors when I (re)install the plugin, but trying to execute the function gives me the following error:

Compile error
World: longsword (master)
Immediate execution
[string "Command line"]:1: '=' expected near '<eof>'

Vinícius
[Go to top] top

Posted by VBMeireles   Brazil  (47 posts)  [Biography] bio
Date Reply #1 on Fri 18 Mar 2016 02:51 PM (UTC)
Message
I'm trying to setup an internal area list for manipulation through scripting and posterior importing/exporting to a "physical" database.

I have a very small programming background, but I've been slowly beginning to do experiment with Lua and I've come up with the following (it's in my plugin file's script CDATA) in order to implement such a list:

area_list = {
  area = {
    name,
    age_range = {
      min,
      max
    },
    coordinates = {
      x,
      y
    },
    monster_list = {},
    task_list = {}
  }
}

function fn_area_list()
  i = 1
  while area_list<i> do
    Note(area_list<i>["name"])
    i = i + 1
  end
end


It gives me no loading errors when I (re)install the plugin, but trying to execute the function gives me the following error:

Compile error
World: longsword (master)
Immediate execution
[string "Command line"]:1: '=' expected near '<eof>'

Vinícius
[Go to top] top

Posted by VBMeireles   Brazil  (47 posts)  [Biography] bio
Date Reply #2 on Fri 18 Mar 2016 03:08 PM (UTC)
Message
I'm sorry about the confusion, but the "error" brought above is no more.

The real error is as follows. I try to call the function declared in the plugin (as explained above) by typing
/fn_area_list()
but it gives me the following result:

Run-time error
World: longsword (master)
Immediate execution
[string "Command line"]:1: attempt to call global 'fn_area_list' (a nil value)
stack traceback:
        [string "Command line"]:1: in main chunk

Vinícius
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Fri 18 Mar 2016 05:37 PM (UTC)
Message
When pasting code into the forum you currently need to use the Convert Clipboard Forum Codes feature in MUSHclient first as described in this thread: http://www.mushclient.com/forum/?id=9691

Can you go back and edit/consolidate your posts to make the issue more clear?




Hey Nick, maybe the forum could ignore other tags found between code tags?

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by VBMeireles   Brazil  (47 posts)  [Biography] bio
Date Reply #4 on Fri 18 Mar 2016 07:03 PM (UTC)
Message
I wish I could preview my messages before sending them or edit them afterwards without being blocked by "spam prevention" (I'm under security policies, so I'm not sure if that (cookie issues?) is causing the "spam prevention" blocks).

Anyway, let me try to be more clear and concise:

I have a world in which I installed a plugin which contains the following alias:

<alias name="as_area_list" match="^area list$" enabled="y" group="asgp_area" regexp="y" send_to="12" sequence="100">
  <send>
    Note("AREA LIST")
    i = 1
    while area_list[i] do
      Note(area_list[i]['name'])
      i = i + 1
    end
    fn_area_list()
  </send>
</alias>


In the CDATA part of my plugin (which was generated by MUSHclient's plugin wizard) I have put the following piece of code:

<script>
<![CDATA[


...

function fn_area_list()
  i = 1
  while area_list[i] do
    Note(area_list[i]["name"])
    i = i + 1
  end
end


...

]]>
</script>


When I go to my world and type area list into the command bar and hit ENTER, I get "AREA LIST" (and nothing else) twice.

Note that the alias not only has the code in itself (that's why I get the area_list output ONCE), but also a call to the function which, as shown above, does the same thing. That tells me the alias is not only working, but the function declared into the plugin's CDATA is also working when called from within the alias.

FIRST PROBLEM
If I go to the world's command bar and type "/fn_area_list()" and hit ENTER, I receive the following result:

Run-time error
World: longsword (master)
Immediate execution
[string "Command line"]:1: attempt to call global 'fn_area_list' (a nil value)
stack traceback:
        [string "Command line"]:1: in main chunk


First question: Why does the function work for the alias, but not for my command input? It looks like my world treats the function as not declared while the alias treats it as declared?

SECOND PROBLEM
If I go to my world's command input and type /Note(area_list[1]['name']), I get "ashendell" as output, but at the same time my while loop doesn't seem to be retrieving anything at all from the array since I get only "AREA LIST" but nothing else from calling the function.

Second question:
What's wrong with my while loop?

Vinícius
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #5 on Fri 18 Mar 2016 08:29 PM (UTC)

Amended on Fri 18 Mar 2016 08:51 PM (UTC) by Nick Gammon

Message
Quote:
First question: Why does the function work for the alias, but not for my command input? It looks like my world treats the function as not declared while the alias treats it as declared?

That's just how plugins work. You'll have to use CallPlugin.
http://www.mushclient.com/scripts/function.php?name=CallPlugin

Quote:
What's wrong with my while loop?

Nothing*. The problem is where you're storing the data. As far as the plugin knows, the area list table is empty. Plugins have their own encapsulated run environments and don't share script variables with other plugins or the main world.

* - But that's not the cleanest way to loop over a list.
You should consider using:

for i,area in ipairs(area_list) do
   Note(area['name']) -- area here is equivalent to area_list[i]
end

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Fri 18 Mar 2016 08:48 PM (UTC)

Amended on Fri 18 Mar 2016 08:49 PM (UTC) by Nick Gammon

Message
@VBMeireles :

Template:codetag To make your code more readable please use [code] tags as described here.


Read the part about "converting forum codes".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Fri 18 Mar 2016 08:53 PM (UTC)
Message
Fiendish said:

Hey Nick, maybe the forum could ignore other tags found between code tags?


If it did it might not be backwards compatible with existing posts. I suppose for new ones it could auto-convert them. It would have to detect if you have already converted them and not do it twice.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by VBMeireles   Brazil  (47 posts)  [Biography] bio
Date Reply #8 on Fri 18 Mar 2016 10:12 PM (UTC)
Message
@Nick

I was pasting from Notepad++ where I edit the plugin.

Vinícius
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #9 on Fri 18 Mar 2016 11:26 PM (UTC)
Message
Nick Gammon said:

Fiendish said:

Hey Nick, maybe the forum could ignore other tags found between code tags?


If it did it might not be backwards compatible with existing posts.

That's true, but maybe ok? How often does someone actually want italics inside their code?

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Sat 19 Mar 2016 05:11 AM (UTC)
Message
Sometimes when making a point I put bold inside code. As in "and now, these amended lines do ...".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #11 on Sat 19 Mar 2016 03:44 PM (UTC)
Message
Nick Gammon said:

Sometimes when making a point I put bold inside code. As in "and now, these amended lines do ...".

That's a good point. Maybe just ignore [i] then because of common convention? Or change [i] and [b] to [italic] and [bold]? That's probably more reliable, and then a one-time find/replace could be run over the whole forum to get it up to speed.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Sun 20 Mar 2016 02:20 AM (UTC)
Message

test end test

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Sun 20 Mar 2016 02:22 AM (UTC)
Message
I'm reluctant to do too much auto-changing of what people write. I've detected (I think) un-escaped square brackets inside code tags, and now give a warning.

I was going to make it an error, but then I realized I couldn't do the very thing I wanted - make parts of code in bold, if I did that.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #14 on Sun 20 Mar 2016 11:08 AM (UTC)

Amended on Sun 20 Mar 2016 11:09 AM (UTC) by Fiendish

Message
Nick Gammon said:

I\'m reluctant to do too much auto-changing of what people write.

I think that any instances of "[i]...[/i]", "[b]...[/b]" you find will be necessarily unescaped and therefore always formatting and not literal, which would make them always safe to convert to a new format tag style. This auto-conversion would happen only once, not for each new post. New posts would have to conform to the new "[italic]"/"[bold]" tags.

https://github.com/fiendish/aardwolfclientpackage
[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.


42,538 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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 HostDash]