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
➜ Variables using text
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Terry
USA (87 posts) 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? | Top |
|
Posted by
| StuDraKi
Germany (17 posts) 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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:
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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 | Top |
|
Posted by
| Terry
USA (87 posts) 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #6 on Thu 31 Jan 2008 04:02 AM (UTC) |
Message
| |
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.
24,866 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top