Operators Help
#1

Okay,
Im trying to script a little something and Im getting an error.
Could somebody please correct me on this.

I'm doing this

pawn Код:
if(weaponid >= 1 || =< 15)
And I get this error on that Line

pawn Код:
error 029: invalid expression, assumed zero
Please any help?
Reply
#2

pawn Код:
if(weaponid >= 1 || weaponid =< 15)
Reply
#3

Okay so I have done
pawn Код:
if(weaponid >= 1 || weaponid =< 15)
And Now I get Errors on that same line.
pawn Код:
(34) : warning 211: possibly unintended assignment
(34) : error 022: must be lvalue (non-constant)
(34) : error 029: invalid expression, assumed zero
(34) : warning 215: expression has no effect
(34) : error 001: expected token: ";", but found ")"
(34) : fatal error 107: too many error messages on one line
Above this code I have:
pawn Код:
new weaponid = GetPlayerWeapon(playerid);
Reply
#4

pawn Код:
if(weaponid > 0 || weaponid < 16)
EDIT: ****** is faster...
Reply
#5

Okay so I used
pawn Код:
&&
But now I am doing another line

I am doing
pawn Код:
if(weaponid > 15 && < 19 || == 39)
What am I doing wrong there cos I am getting these errors.
pawn Код:
(47) : error 029: invalid expression, assumed zero
(47) : error 029: invalid expression, assumed zero
(47) : warning 215: expression has no effect
(47) : error 001: expected token: ";", but found ")"
(47) : fatal error 107: too many error messages on one line
Reply
#6

you still have to write weaponid again.
pawn Код:
if(weaponid > 15 && weaponid  < 19 || weaponid  == 39)
Quote:
Originally Posted by ******
Посмотреть сообщение
"OR" is commutative, so doing things one way is the same as doing them the other (MOSTLY). So your code is the same as doing:

pawn Код:
if (=< 15 || weaponid >= 1)
Hopefully that shows you why what you wrote is wrong (apart from the fact that's it's "<=", not "=<") - 15 is not compared to anything. Also, assuming you write this expression correctly, when will it fail? EVERY number is either greater than 1 or less than 15. 16 is not less than 15, but it is greater than 1, so the test will pass. -100 is not greater than 1, but it is less than 15, so the test will pass.

I said "mostly" above because OR has a feature called "short-circuiting":

pawn Код:
func(&i)
{
    ++i;
    return true;
}

main()
{
    new i = 5;
    if (i > 1 || func(i)) printf("%d", i);
}
That will print "5", not "6" because "func" is never called. The first part of the OR passes, so there's no point checking the second part.
Reply
#7

Quote:
Originally Posted by Deduction
Посмотреть сообщение
Okay so I used
pawn Код:
&&
But now I am doing another line

I am doing
pawn Код:
if(weaponid > 15 && < 19 || == 39)
What am I doing wrong there cos I am getting these errors.
pawn Код:
(47) : error 029: invalid expression, assumed zero
(47) : error 029: invalid expression, assumed zero
(47) : warning 215: expression has no effect
(47) : error 001: expected token: ";", but found ")"
(47) : fatal error 107: too many error messages on one line
You should re-read what ****** said, doing

if(weaponid > 15 && < 19 || == 39)

is wrong, if you were to break it down, you're checking "== 39" .. that makes no sense, what equal to 39? You have to do || weaponid == 39), because if you don't you're not comparing anything.
Reply
#8

So Something like this?:

pawn Код:
if(weaponid >= 15 && <= 19 || weaponid = 39)
And ******, I am having trouble figuring out how this would even work.
pawn Код:
main()
{
    new i = 5;
    if (i > 1 || func(i)) printf("%d", i);
}
Starting to confuse me.
Reply
#9

Always, you should compare Left to Right.
Код:
Left Comparison_Operator Right
== 39 is wrong, you need the left.
Reply
#10

I still don't understand.
Im trying to do what ****** is saying, but I am still getting errors.
WTF?
pawn Код:
if(weaponid > 15 && < 19 || weaponid == 39)
What part of that line am I doing thats wrong?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)