Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   booleans, can I do this? (https://forums.graalonline.com/forums/showthread.php?t=81376)

Frankie 08-22-2008 02:12 AM

booleans, can I do this?
 
PHP Code:

setlevel2((player.guild == "Convict" && player.level != "era_prison-break.nw""era_present_00-00.nw""era_prison-break.nw"), 3030); 

with the 2 checks?

cbk1994 08-22-2008 02:24 AM

Try this:
PHP Code:

setlevel2(((player.guild == "Convict" && player.level.name != "era_prison-break.nw" ) ? "era_presemt_00-00.nw" "era_prison-break.nw"), 3030); 


xXziroXx 08-22-2008 04:25 AM

Quote:

Originally Posted by cbk1994 (Post 1416416)
Try this:
PHP Code:

setlevel2(((player.guild == "Convict" && player.level.name != "era_prison-break.nw" ) ? "era_presemt_00-00.nw" "era_prison-break.nw"), 3030); 


I agree on the player.level.name fix, but adding another bracket around it was just stupid. :noob:

zokemon 08-22-2008 11:14 AM

Quote:

Originally Posted by xXziroXx (Post 1416434)
I agree on the player.level.name fix, but adding another bracket around it was just stupid. :noob:

It wasn't stupid, adding a parentheses around the entire expression was the pointless part.

This will work just find:

PHP Code:

 setlevel2((player.guild == "Convict" && player.level != "era_prison-break.nw") ? "era_present_00-00.nw" "era_prison-break.nw"3030); 

If you did want to keep those parentheses though, you could do something even cooler:

PHP Code:

 setlevel2("era_" @ ((player.guild == "Convict" && player.level != "era_prison-break.nw") ? "present_00-00" "prison-break") @ ".nw"3030); 

The comma operator will automatically parse the whole set of arguments and end whatever expression you put in the first argument of the function unless there is an unbalanced/unclosed parentheses (which should be fixed anyways). You can leave extra parentheses though, it just can be rather difficult (or at least annoying) when dealing with 3+ sets of them nested together.

Inverness 08-22-2008 08:38 PM

Holy crap what's wrong with you people.

That script may work but it looks horrible.

PHP Code:

if (player.guild == "Convict" && player.level.name != "era_prison-break.nw") {
  
player.setlevel2("era_present_00-00.nw"3030);


When you script you need to consider that other people will be reading your script in the future. Don't over-complicate things just because you can.

xXziroXx 08-22-2008 08:42 PM

Quote:

Originally Posted by Inverness (Post 1416540)
PHP Code:

if (player.guild == "Convict" && player.level.name != "era_prison-break.nw") {
  
player.setlevel2("era_present_00-00.nw"3030);
} else 
player.setlevel2("era_prison-break.nw"3030); 


Fixed. :rolleyes:


Also, I'm not agreeing with the way he did it, but the thread wasn't made to argue about that.

Inverness 08-22-2008 08:45 PM

Quote:

Originally Posted by xXziroXx (Post 1416544)
Fixed. :rolleyes:

PHP Code:

if (player.guild == "Convict" && player.level.name != "era_prison-break.nw") {
  
player.setlevel2("era_present_00-00.nw"3030);
}
else {
  
player.setlevel2("era_prison-break.nw"3030);


Now it's fixed. Mixing styles like you did looks bad too.
Quote:

Originally Posted by xXziroXx (Post 1416544)
Also, I'm not agreeing with the way he did it, but the thread wasn't made to argue about that.

Doesn't matter why the thread was made. A bad habit (imho) shouldn't be encouraged.

xXziroXx 08-22-2008 08:58 PM

Quote:

Originally Posted by Inverness (Post 1416547)
Doesn't matter why the thread was made. A bad habit (imho) shouldn't be encouraged.

Ignoring it completely isn't the same as encouraging, which I definitely wasn't doing, as you can see in my first post in the thread.

zokemon 08-22-2008 09:24 PM

Quote:

Originally Posted by Inverness (Post 1416540)
Holy crap what's wrong with you people.

That script may work but it looks horrible.

PHP Code:

if (player.guild == "Convict" && player.level.name != "era_prison-break.nw") {
  
player.setlevel2("era_present_00-00.nw"3030);


When you script you need to consider that other people will be reading your script in the future. Don't over-complicate things just because you can.

Wow.

Tigairius 08-22-2008 11:28 PM

Quote:

Originally Posted by Inverness (Post 1416540)
Don't over-complicate things just because you can.

It may be over complicated for you, but it looks fine to me.

WhiteDragon 08-22-2008 11:41 PM

Quote:

Originally Posted by Tigairius (Post 1416643)
It may be over complicated for you, but it looks fine to me.

I agree. I fail to understand how a common alternative syntax to if statements would be "complicated" to anyone. If they fail to read it correctly then I don't want them touching my code anyways.

I do agree that they should not be used beyond one level of nesting though, because then the same syntax is being used multiple times in one line which can be an eyesore.

Switch 08-23-2008 12:01 AM

Quote:

Originally Posted by Inverness (Post 1416540)
Holy crap what's wrong with you people.

That script may work but it looks horrible.

PHP Code:

if (player.guild == "Convict" && player.level.name != "era_prison-break.nw") {
  
player.setlevel2("era_present_00-00.nw"3030);


When you script you need to consider that other people will be reading your script in the future. Don't over-complicate things just because you can.

He was asking for if he could do it with booleans, as in not an if(){}else{}.

Codein 08-23-2008 12:24 AM

Quote:

Originally Posted by Switch (Post 1416668)
He was asking for if he could do it with booleans, as in not an if(){}else{}.

If you think about it, if statements are just a form of writing booleans. I can understand something==somethingelse?function:anotherfunction, but if else statements are much easier to read.

TheStan 08-23-2008 12:30 AM

Quote:

Originally Posted by Codein (Post 1416677)
If you think about it, if statements are just a form of writing booleans. I can understand something==somethingelse?function:anotherfunction, but if else statements are much easier to read.

It's all opinion in the end of it.

xXziroXx 08-23-2008 12:58 AM

Quote:

Originally Posted by TheStan (Post 1416680)
It's all opinion in the end of it.

And guess which version 95% of all programmers would chose?


All times are GMT +2. The time now is 02:32 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.