Area List

Posted by VBMeireles on Fri 18 Mar 2016 02:46 PM — 17 posts, 70,705 views.

Brazil #0
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>'
Amended on Fri 18 Mar 2016 08:48 PM by Nick Gammon
Brazil #1
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>'
Brazil #2
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
USA Global Moderator #3
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?
Brazil #4
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?
USA Global Moderator #5
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
Amended on Fri 18 Mar 2016 08:51 PM by Nick Gammon
Australia Forum Administrator #6
@VBMeireles :

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


Read the part about "converting forum codes".
Amended on Fri 18 Mar 2016 08:49 PM by Nick Gammon
Australia Forum Administrator #7
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.
Brazil #8
@Nick

I was pasting from Notepad++ where I edit the plugin.
USA Global Moderator #9
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?
Australia Forum Administrator #10
Sometimes when making a point I put bold inside code. As in "and now, these amended lines do ...".
USA Global Moderator #11
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.
Australia Forum Administrator #12

test end test
Australia Forum Administrator #13
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.
USA Global Moderator #14
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.
Amended on Sun 20 Mar 2016 11:09 AM by Fiendish
USA #15
VBMeireles said:

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).



After the initial post, just click the refresh page link towards the bottom of the page then you can edit your post without having to wait 20 minutes.

I used to have the same problem until I figured that out.

When you make that first post, if you look at your link you'll notice you're still in that bbshowpost.php and that's whats keeping you from editing your post.

If you see that ? and all that other stuff after it you're good to go.

(like on this page bbshowpost.php?bbsubject_id=13362&page=2 but if just bbshowpost.php then you get that spam prevention when trying to edit your post)
Amended on Sun 20 Mar 2016 02:00 PM by Wuggly
Brazil #16
Thank you! :)