AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [SP]| somevar != someconst ? return -7 : null | and got invalid expresion (https://forums.alliedmods.net/showthread.php?t=275683)

fakuivan 12-05-2015 23:18

[SP]| somevar != someconst ? return -7 : null | and got invalid expresion
 
Hi there!

|Read the title|

Any clean workarounds?

Mathias. 12-05-2015 23:28

Re: [SP]| somevar != someconst ? return -7 : null | and got invalid expresion
 
PHP Code:

int num = (somevar != someconst ? -0)
if (
num)
    return 
num


fakuivan 12-05-2015 23:33

Re: [SP]| somevar != someconst ? return -7 : null | and got invalid expresion
 
Quote:

Originally Posted by Black-Rabbit (Post 2369219)
PHP Code:

int num = (somevar != someconst ? -0)
if (
num)
    return 
num



somevar != someconst ? return -7 : null

I don't want to assign values, retrun and null are supposed to be expressions. I could just do and it's even simpler

Code:

if (somevar != someconst)
    return -7;

:/

KissLick 12-06-2015 03:57

Re: [SP]| somevar != someconst ? return -7 : null | and got invalid expresion
 
PHP Code:

return (somevar != someconst) ? -0


Miu 12-06-2015 08:30

Re: [SP]| somevar != someconst ? return -7 : null | and got invalid expresion
 
can't have statements there o.o

fakuivan 12-06-2015 11:16

Re: [SP]| somevar != someconst ? return -7 : null | and got invalid expresion
 
Quote:

Originally Posted by KissLick (Post 2369240)
PHP Code:

return (somevar != someconst) ? -0


I don't want to return 0, I want to do nothing if the condition evaluates to false

WildCard65 12-06-2015 11:29

Re: [SP]| somevar != someconst ? return -7 : null | and got invalid expresion
 
Quote:

Originally Posted by fakuivan (Post 2369364)
I don't want to return 0, I want to do nothing if the condition evaluates to false

Then use what you posted in https://forums.alliedmods.net/showpo...20&postcount=3

fakuivan 12-06-2015 13:45

Re: [SP]| somevar != someconst ? return -7 : null | and got invalid expresion
 
Quote:

Originally Posted by WildCard65 (Post 2369367)

So, there is no clean way to solve this. I think I will just do

Code:

somevar != someconst ? return -7 : somevar = somevar

Miu 12-06-2015 13:56

Re: [SP]| somevar != someconst ? return -7 : null | and got invalid expresion
 
you can't :V

thecount 12-06-2015 13:56

Re: [SP]| somevar != someconst ? return -7 : null | and got invalid expresion
 
Quote:

Originally Posted by fakuivan (Post 2369396)
So, there is no clean way to solve this.

You can't use 'return' in an expression like that. Best way to get around this is to, god forbid, use an if statement.
PHP Code:

if(somevar != someconst){ return 7; } 



All times are GMT -4. The time now is 10:30.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.