Random Lua Questions

Posted by Falgor on Sun 29 Jan 2017 03:03 PM — 19 posts, 76,105 views.

#0
Hi guys,

I'm in the process of making a COM script that allows MUSHclient to talk to CMUD (to pull data from the map).

Here is it so far:


require("luacom")
require("luacom5")

  cmud = luacom.CreateObject("cMUD.Application")
  cmuds = cmud.CurrentSession
  cmuds:processcommand("go CASTLE")
  var = cmuds.getvar(Route,"Route")
  val = var.value

print(val)


Works fine, but now I'm stuck and after hours of searching the internet still don't have an answer.

Firstly, how would I go about putting a wildcard into the function? I'd want to replace CASTLE with a wildcard word, that would be picked up when the alias is typed.

My attempts so far have failed.

Next I can't figure out how to send (val) to the MUD, I can only print it, I've tried send,execute etc and nothing works.

Thanks in advance for your help.
#1
It gets worse!

I've figured out how to do the above, although not very efficiently I fear!

More pressingly, I've managed to overwrite the "print" command...

I must have made a string called print during my trial and error and now:
<code>//print ("Hello")</code>
<code>
Run-time error
World: The Two Towers
Immediate execution
[string "Command line"]:1: attempt to call global 'print' (a string value)
stack traceback:
[string "Command line"]:1: in main chunk</code>

Is there anywhere I can view all the lua strings/variables I've made so I can delete them, or a function to delete strings?
USA Global Moderator #2
Quote:
Firstly, how would I go about putting a wildcard into the function? I'd want to replace CASTLE with a wildcard word, that would be picked up when the alias is typed.

Perhaps if I change the structure a bit you'll see how to do it...

  my_variable = "CASTLE"
  cmuds:processcommand("go "..my_variable)


Quote:
Next I can't figure out how to send (val) to the MUD, I can only print it, I've tried send,execute etc and nothing works.

Send and Execute are case sensitive.
USA Global Moderator #3
Quote:
More pressingly, I've managed to overwrite the "print" command...

I must have made a string called print during my trial and error and now:

Lol. Just restart MUSHclient and don't do that again! ^_^
#4
Thank you!

I'm getting there slowly :)

So, next hurdle!

I have a list of everyone that is online, and I'm throwing it into a miniwindow, however, if the list is too long, it's too big for the Window!

I can't find anywhere about a word wrap feature for miniwindows so my plan is to cut my list down, and send everything over 100 (20 in my example) characters into the new list. This is what I have, it's only sending over the first word though!


online = "Duck, Goose, Bear, Badger, Owl, Pigeon"
onlinenewline = string.find(oneline, ", (.+), 20"
print (onlinenewline)

RETURNS

201


How can I get it to add everything it sees after the first , 20 characters in, like it doesn't when I "print" it.
USA Global Moderator #5
new subject new thread :) The problem with "random lua questions" is that it makes things hard to find when searching.
Australia Forum Administrator #6
Falgor said:

How can I get it to add everything it sees after the first , 20 characters in, like it doesn't when I "print" it.


As Fiendish says, ask a new question. Making a scrolling window isn't that bad. Fiendish does it for a chat window.
USA Global Moderator #7
Quote:
Making a scrolling window isn't that bad. Fiendish does it for a chat window.


Not that bad?! All together it's probably one of the most terrifying bits of MUSHclient Lua work. ^O^

One of these days, if I can ever get around to it, I want to make drop-in modules for "Make me a resizable miniwindow that I can drag around", "Now add a scrolling/highlightable text box at these coordinates with a default context menu for basic copy actions", "Now add a scrollbar at these coordinates with bidirectional scrolling events bound to the text box", "Now add additional context menu items". This is of course the way I should have done it in the first place, except it was all so experimental back then. I keep promising myself that I'll get to it one day.
Amended on Sun 29 Jan 2017 09:53 PM by Fiendish
Australia Forum Administrator #8
Falgor said:

This is what I have, it's only sending over the first word though!

...

How can I get it to add everything it sees after the first , 20 characters in, like it doesn't when I "print" it.


Your example has multiple typos, and a quote in the wrong spot. This does it:


oneline = "Duck, Goose, Bear, Badger, Owl, Pigeon, Goat, Magnet"
idx = string.find(oneline, " ", 20)
print (string.sub (oneline, idx))


Output:


 Owl, Pigeon, Goat, Magnet
Australia Forum Administrator #9
Fiendish said:

Quote:

Making a scrolling window isn't that bad. Fiendish does it for a chat window.

Not that bad?! All together it's probably one of the most terrifying bits of MUSHclient Lua work. ^O^



OK, just to make things easier, I wrote a plugin that lets you set up (one) scrolling miniwindow:

http://www.gammon.com.au/forum/?id=13916

You could probably extend it to handle more than one window with a bit of work.

Note that unlike Fiendish's fancy windows used in Aardwolf, this one does not implement resizing dynamically. You can however drag it around, and copy its contents.
Amended on Tue 31 Jan 2017 11:23 AM by Fiendish
USA Global Moderator #10
Nick Gammon said:

Note that unlike Fiendish's fancy windows used in Aardwolf, this one does not implement resizing dynamically. You can however drag it around, and copy its contents.

No wrapping, no resize, no interactive text selection, no url detection for underlined hyperlinks, no proportionally-sized slider.
But yours is simple, clean, and pretty, which is better as a demo. The decision to make it a plugin instead of a require module seems odd, though.
Amended on Tue 31 Jan 2017 11:26 AM by Fiendish
USA Global Moderator #11
Quote:
I can't find anywhere about a word wrap feature for miniwindows...

Anyway, Nick seems to have forgotten, but he already wrote a chat window demo that wraps lines. It's in this thread: http://gammon.com.au/forum/?id=9996
Australia Forum Administrator #12
Fiendish said:

Nick Gammon said:

Note that unlike Fiendish's fancy windows used in Aardwolf, this one does not implement resizing dynamically. You can however drag it around, and copy its contents.

No wrapping, no resize, no interactive text selection, no url detection for underlined hyperlinks, no proportionally-sized slider.
But yours is simple, clean, and pretty, which is better as a demo.


I was feeling lazy. But at least it shows the idea. I've added wrapping (and UTF-8 as an option) as I thought that would be useful.

You have outlined however why your version took a lot of work - it's surprising how much goes into a simple text window. :)
Netherlands #13
I have on occasion considered adding scrolling support to one of my plugins.. and just no. It's just not worth it in terms of the headache that is said plugin already, sadly enough. :-/
Australia Forum Administrator #14
Well, now you can just shove text to my plugin. :)

However I haven't allowed for multiple windows. Fiendish's suggestion of a module rather than a plugin might help. Alternatively have some sort of "window name" idea where you maintain multiple window states.

I'll leave that as an exercise for the more enthusiastic readers. :P
Netherlands #15
Nah, it would make more sense to hack it into my own. I have some rather esoteric needs in this plugin or I would not have reinvented the wheel. :-/
Australia Forum Administrator #16
I enhanced the plugin a few times. Now it can handle embedded newlines when you go to add more lines. You can also change the font interactively.
Netherlands #17
The plugin is my old Previewer plugin which I use to simulate game commands. (Yay color codes, special syntactual identifiers or other complicated MUSH commands.)

It goes out of its way to resemble MUSHclient's own rendering as much as humanly possible. On its own that should not be too hard, but since I also combine this with applying spell-checking, red 'Word squiggles' to match misspelled words as well as the tracking of positions in the command window, the implementation tends to get rather complicated on a lot of different layers.

In theory, I ought to be able to split things like wrapping, rendering, spell-checking and other such happy stuff into perfectly individual functions... but they end up relying on each other just a bit too often in more or less subtle ways.

Besides, if I end up implementing it, I probably need to do so in a way that supports my architecture where all the visual stuff has been split off into its own module for maximum visual customizability. Which means I need to go back to figuring out how all of that worked, how it needs to change to support scrolling, and finally cry over the fact it probably wasn't worth it.

That plugin basically implements the client and server at the same time. It is an utter nightmare, yet I keep coming back to it every so often. xD
Australia Forum Administrator #18
If you have a function that draws the text (with whatever level of complexity) then scrolling basically just offsets the Y starting point (ie. you start drawing above the window).

So instead of starting at Y=0, you start at Y=-400 or whatever so that you don't actually see the part you have scrolled past.

Having done that you just draw a scroll bar with a thumb in the appropriate place.