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?

Codein 08-23-2008 01:06 AM

Quote:

Originally Posted by xXziroXx (Post 1416695)
And guess which version 95 percent of all programmers would chose?

I wouldn't know. I'm a bit of an amatuer when it comes to coding practices. Please tell me what 95 percent of programmer would choose :)

DrakilorP2P 08-23-2008 01:38 AM

Quote:

Originally Posted by xXziroXx (Post 1416695)
And guess which version 95% of all programmers would chose?

Why, yours of course.

Frankie 08-23-2008 02:28 AM

I wasn't asking for a better/neater way to do it.
I wasn't even planning on using that code. I was writing a boolean then realized I had to add another "if statement" and I wondered if it's even possible.

and I've used just player.level for the longest time and it works fine. what exactly does adding the .name do?

xXziroXx 08-23-2008 02:48 AM

Quote:

Originally Posted by Frankie (Post 1416725)
and I've used just player.level for the longest time and it works fine. what exactly does adding the .name do?

player.level is an object, player.level.name refers to the name of that object.

Inverness 08-23-2008 03:34 AM

Quote:

Originally Posted by xXziroXx (Post 1416729)
player.level is an object, player.level.name refers to the name of that object.

Indeed, I think the reason you can still compare player.level to a string is because either Stefan is compensating some how or its comparing with the object's name when you have a string in some weird way that Stefan doesn't bother to document for us.
Quote:

Originally Posted by zokemon (Post 1416564)
Wow.

Elaborate
Quote:

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

what makes you think it is over complicated for me?

I apologize for thinking that other people may not be able to understand such things as easily or as quickly as myself.

I also apologize for suggesting to use code that is clearer at first glance and doesn't require you to scroll so far to see the whole statement.

Codein 08-23-2008 04:27 AM

Quote:

Originally Posted by Inverness (Post 1416736)
Indeed, I think the reason you can still compare player.level to a string is because either Stefan is compensating some how or its comparing with the object's name when you have a string in some weird way that Stefan doesn't bother to document for us.
Elaborate
what makes you think it is over complicated for me?

I apologize for thinking that other people may not be able to understand such things as easily or as quickly as myself.

I also apologize for suggesting to use code that is clearer at first glance and doesn't require you to scroll so far to see the whole statement.

You're totally right.

DrakilorP2P 08-23-2008 05:24 PM

Quote:

Originally Posted by Inverness (Post 1416736)
Indeed, I think the reason you can still compare player.level to a string is because either Stefan is compensating some how or its comparing with the object's name when you have a string in some weird way that Stefan doesn't bother to document for us.

I think it's just "converting" to a string whenever appropriate, which isn't entirely uncommon for a programming language to do. This works for TServerNPC and TServerPlayer as well.

Inverness 08-23-2008 07:00 PM

Quote:

Originally Posted by DrakilorP2P (Post 1416792)
I think it's just "converting" to a string whenever appropriate, which isn't entirely uncommon for a programming language to do. This works for TServerNPC and TServerPlayer as well.

These are things I would like Stefan to document.


All times are GMT +2. The time now is 11:22 PM.

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