Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Gaem
(10 posts) bio
|
| Date |
Thu 07 Dec 2006 10:36 PM (UTC) [ quote
] |
| Message |
I'm sure this question has probably been asked before, but I can't seem to find an answer in the usual documentation places.
I've run into a problem where I'm trying to compare two strings (from variables in MUSH), but modifying one with arithmetic.
eg.
function f1 (name, line, wildcards)
local variable1 = GetVariable("variable1")
local variable2 = GetVariable("variable2")
local variable3 = GetVariable("variable3")
if variable1 < 0.85 * variable2 then (here I have a problem, since it says I can't do arithmetic on a string)
Note ("yay!")
end
end -- function
Also, what is the syntax in lua for conditioning on 2 variables? So, as above, but requiring variable3 = 1 as well as variable1 < 0.85 * variable2.
Thanks | top |
|
| Posted by |
Nick Gammon
Australia (18,772 posts) bio
Forum Administrator |
| Date |
Reply #1 on Thu 07 Dec 2006 10:44 PM (UTC) [ quote
] |
| Message |
|
| Posted by |
Gaem
(10 posts) bio
|
| Date |
Reply #2 on Fri 08 Dec 2006 12:16 AM (UTC) [ quote
] |
| Message |
Thanks!
The first part works fine, but I get this error whenever I try to do if statements with 2 parts;
compile error
[string "Script file"]:63: 'then' expected near '='
I was using
if tonumber(var1) < 0.85 * tonumber(var2) and var3 = 1 then
as the line.
Any ideas as to what I'm doing wrong? | top |
|
| Posted by |
Nick Gammon
Australia (18,772 posts) bio
Forum Administrator |
| Date |
Reply #3 on Fri 08 Dec 2006 12:31 AM (UTC) [ quote
] |
| Message |
Equality test is == not =.
Inequality is ~= (in Lua).
So yours should read:
if tonumber(var1) < 0.85 * tonumber(var2) and var3 == 1 then
The "=" operator is assignment. Thus you can write this:
This makes a true if b is equal to 2, false otherwise. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
| Posted by |
Gaem
(10 posts) bio
|
| Date |
Reply #4 on Fri 08 Dec 2006 08:45 AM (UTC) [ quote
] |
| Message |
Thanks again!
That all works fine now.
| 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.
1,490 views.
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )