- Home /
if not bigger then.
I need a if statement which states if ( tijdvak = not smaller then 0 and not bigger then 5) tijdvak is a variable
I tried to solve it by
if ( tijdvak !<0 && tijdvak !> 5){
}
the problem is that this gives me errors.
Expecting ), found ! unexpected token: < ';' expected. Insert a semicolon at the end
and it goes through with every symbol, except the numbers. Unity does not want to recognize that my code does not end at the first ! Is this a bug, or am I doing something wrong?
The weird part however is that the first time I tried this, it worked, now Unity doesn't let me.
It never would have worked; that's invalid syntax and will always generate an error.
Answer by Chris D · Jan 19, 2012 at 05:42 AM
Is there any rationale behind using those comparisons? If not, just use
if (tijdvak >= 0 && tijdvak <= 5){
...
}
See the MSDN docs for the standard comparison syntax.
Or if you like the NOT-operator:
if (!(tijdvak < 0) && !(tijdvak > 5)){
...
}
And if you prefer equivalent logical statement with OR operator:
if (!(tijdvak < 0 || tijdvak > 5)){
...
}
@$$anonymous$$ryptos that doesn't work, Unity still thinks there should be a ) ins$$anonymous$$d of a !
i've abandoned this method. It worked one time, but i figured out that i need something else for the rest of the code to actually work for me. Thanks anyway :)
Even though i'm new, Unity sometimes is a lil illogical.
@TristanSchaaf sorry but my syntax IS correct. If it doesn't work then let's assume it has something to do with your logic or maybe there is a syntax error in the previous lines of code.
@TristanSchaaf: you're mistaken--one thing Unity is, is relentlessly logical. Something will never work just once...it either works or doesn't, always.
Somehow, it did with me, or my memmory is blurred. Dunno why or how, whatever. I fixed it through an entire other code. Still one thing Unity is relentless, all though for me illogical, coordinates, local, world, GUI... but that's another thing all together