Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
Are you wanting the If condition to be True when the value is not equal to either of your variables?
Something in the lines of this, maybe?
Not a LUA-expert, but some coding experience.
currently I've got 2 other if statements above the problem one,
if(codeValue == ABCD)
then
XYZ
end
if(codeValue == 1234)
then
123
end
if(codeValue ~= ABCD or 1234 )
then
"NOT WORK PROPERLY"
end
Probably not the most optimised way of doing it I know but I don't know any other way.
And I thought the same Rasputin, when you use an operator in the script it colours it purple and this doesn't happen with "!="
if (codeValue == 1234) then foo(x) end
vs.
if (codeValue == 1234) foo(x);
So much excess writing
If codevalue = ABCD
then xyz
Elseif codevalue = 1234
then 123
Else something
end
'if( x ~= ABCD and x ~= EFGH )' is the same as 'if not (x == ABCD or x == EFGH)'
You have to consider the or-argument isn't what you read out in plain English.
See more here if you like:
De Morgan's Laws[en.wikipedia.org]
Yeah, don't like the '~='-syntax myself. It is very unintuitive on the keyboard :P
I don't entirely understand why this works but it does so thank you.
And also I originally thought ~= meant roughly equal to instead.
Nice! Glad you got it working.
To sum it up, you were telling the program to evaluate
- x ~= ABCD (true or false depending on the situation)
or
- 1234 (which if it is not nil is true)
(true) or true is : true, (false) or true is : also true, thus your condition was always true, hence the program was not behaving like you expected it to.
EG:
If codevalue = ABCD
then xyz
Elseif codevalue = 1234
then 123
Elseif codevalue >= XYZ
then
Elseif codevalue <= 9876
then
Else something
end
Would this work?
Yes, but it will stop where the expression is true and not test more expressions.
(EDIT: Which is a good thing! Writing multiple IF's is forcing the script to check each statement. ELSEIF's can improve performance)
See syntax:
LUA IF ELSEIF ELSE[www.tutorialspoint.com]
Exactly! As I said the OR-operator is not what you read out in plain English and the OR-operator comes last in the precedence - it is evaluated last.
But that guy explained it better than I can :)