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 ➜ Random Lua Questions

Random Lua Questions

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


Pages: 1 2  

Posted by Falgor   (36 posts)  Bio
Date Sun 29 Jan 2017 03:03 PM (UTC)
Message
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.
Top

Posted by Falgor   (36 posts)  Bio
Date Reply #1 on Sun 29 Jan 2017 07:09 PM (UTC)
Message
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?
Top

Posted by Fiendish   USA  (2,537 posts)  Bio   Global Moderator
Date Reply #2 on Sun 29 Jan 2017 07:11 PM (UTC)
Message
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.

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

Posted by Fiendish   USA  (2,537 posts)  Bio   Global Moderator
Date Reply #3 on Sun 29 Jan 2017 07:13 PM (UTC)
Message
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! ^_^

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

Posted by Falgor   (36 posts)  Bio
Date Reply #4 on Sun 29 Jan 2017 07:27 PM (UTC)
Message
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.
Top

Posted by Fiendish   USA  (2,537 posts)  Bio   Global Moderator
Date Reply #5 on Sun 29 Jan 2017 08:33 PM (UTC)
Message
new subject new thread :) The problem with "random lua questions" is that it makes things hard to find when searching.

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

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #6 on Sun 29 Jan 2017 09:18 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Fiendish   USA  (2,537 posts)  Bio   Global Moderator
Date Reply #7 on Sun 29 Jan 2017 09:44 PM (UTC)

Amended on Sun 29 Jan 2017 09:53 PM (UTC) by Fiendish

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

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

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #8 on Mon 30 Jan 2017 04:44 AM (UTC)
Message
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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #9 on Tue 31 Jan 2017 04:51 AM (UTC)

Amended on Tue 31 Jan 2017 11:23 AM (UTC) by Fiendish

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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Fiendish   USA  (2,537 posts)  Bio   Global Moderator
Date Reply #10 on Tue 31 Jan 2017 11:25 AM (UTC)

Amended on Tue 31 Jan 2017 11:26 AM (UTC) by Fiendish

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

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

Posted by Fiendish   USA  (2,537 posts)  Bio   Global Moderator
Date Reply #11 on Tue 31 Jan 2017 11:30 AM (UTC)
Message
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

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

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #12 on Tue 31 Jan 2017 10:21 PM (UTC)
Message
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. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #13 on Tue 31 Jan 2017 11:41 PM (UTC)
Message
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. :-/
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #14 on Wed 01 Feb 2017 12:43 AM (UTC)
Message
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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


56,886 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 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.