[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]  Lua
. . -> [Subject]  Variables using text
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Variables using text

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


Posted by Terry   USA  (87 posts)  [Biography] bio
Date Wed 30 Jan 2008 12:06 PM (UTC)
Message
There have been a few times that I've tried to use a wildcard which picked up text. However, whenever I've tried to use the corresponding variable, MUSHclient always said something about comparing numbers and text. Is there a way to use text in ifchecks?
[Go to top] top

Posted by StuDraKi   Germany  (17 posts)  [Biography] bio
Date Reply #1 on Wed 30 Jan 2008 04:38 PM (UTC)
Message
Can you provide us with a short example, e.g. using the plugin wizard to extract one trigger with the code you try to use?
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Wed 30 Jan 2008 06:53 PM (UTC)
Message
Here is an example of the error:


print ("5" > 6)   --> Error:  attempt to compare number with string


You can convert strings to numbers. Wildcards in triggers and aliases are returned as strings, so they must be converted under certain circumstances.


print (tonumber ("5") > 6) --> false



In some cases Lua can deduce what is required by the operator, eg:


print ("5" + 2) --> 7

- Nick Gammon

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

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #3 on Wed 30 Jan 2008 09:15 PM (UTC)
Message
Words of warning: Make sure to check for sane values before converting a string into a number. Ordinarily, coercion is automatic, so if your script is throwing an error, it might just be due to bad data.
Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
> =tonumber( 9 )
9
> =tonumber( "9" )
9
> =tonumber( "F" )
nil
> =tonumber( "1,000" )
nil
> =tonumber( nil )
nil
> = tonumber( "F" ) > 9
stdin:1: attempt to compare number with nil
stack traceback:
        stdin:1: in main chunk
        [C]: ?
>

It is much easier to fight for one's ideals than to live up to them.
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Wed 30 Jan 2008 10:04 PM (UTC)
Message
Agreed.

However if you use a regular expression in your trigger, and make sure that the wildcard in question must be a sequence of numeric digits, then you have eliminated that problem.

- Nick Gammon

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

Posted by Terry   USA  (87 posts)  [Biography] bio
Date Reply #5 on Thu 31 Jan 2008 03:24 AM (UTC)
Message
I was talking about having strings compared to strings. Like if %1 = "billy" or something. Is that possible?
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Thu 31 Jan 2008 04:02 AM (UTC)
Message
See http://www.mushclient.com/faq point 32.

- Nick Gammon

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


6,246 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]