Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-08-2006, 10:03 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
onwall and such

can someone thuroghly explain onwall,onwall2, onwater, and things of the such. Please. The wiki doesnt help much for me.
__________________
Deep into the Darkness peering...
  #2  
Old 05-09-2006, 02:06 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
onwall(2) detects if a tile is blocking. onwater(2) detects if a tile is water. onwall and onwater check a single tile, while onwall2 and onwater2 check an area of tiles.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #3  
Old 05-09-2006, 05:45 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by ApothiX
onwall(2) detects if a tile is blocking. onwater(2) detects if a tile is water. onwall and onwater check a single tile, while onwall2 and onwater2 check an area of tiles.
onwater/onwater2 checks for lava and water tiles
onwall/onwall2 checks for anything that should be blocking according to the default system (includes players/npcs).

onwall(x,y) tells you if the specified coordinate is blocked
onwall2(x,y,w,h) tells you if there is anything blocking within the specified area
  #4  
Old 05-09-2006, 10:28 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
ok thanks, I got it BUT, with onwall2 is it possible to just detect a blocking tile without specific coordinates? like this.x???
__________________
Deep into the Darkness peering...
  #5  
Old 05-09-2006, 10:41 PM
Shaun Shaun is offline
Registered User
Shaun's Avatar
Join Date: Jul 2003
Location: Canada
Posts: 1,070
Shaun is a jewel in the roughShaun is a jewel in the rough
Yes. For movement systems, people use player.x and player.y to detect. The onwall2 function will put in the value of this.x for the x-coordinate to be checked.
  #6  
Old 05-09-2006, 10:59 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
so it would be like this?

if (onwall2(player.x,player.y-0.5)) {

if so how can I make so it doesnt need to read one the variables and just one of them.
__________________
Deep into the Darkness peering...
  #7  
Old 05-09-2006, 11:05 PM
Shaun Shaun is offline
Registered User
Shaun's Avatar
Join Date: Jul 2003
Location: Canada
Posts: 1,070
Shaun is a jewel in the roughShaun is a jewel in the rough
Not quite...

onwall2(x,y,width,height) returns a boolean value (true or false value).

So if you wanted to see if the left side of a player was blocking, for example, it would look something like this:

if (onwall2(player.x,player.y+1,1/16,2)==true) {
player.blockleft = true;
}
else {
player.blockleft = false;
}
  #8  
Old 05-09-2006, 11:06 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
oh I see. Thank you much. ^.^

EDIT: Okay, it work on all walls but down and right... ?
__________________
Deep into the Darkness peering...

Last edited by Angel_Light; 05-09-2006 at 11:34 PM..
  #9  
Old 05-10-2006, 12:01 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Shaun
Not quite...

onwall2(x,y,width,height) returns a boolean value (true or false value).

So if you wanted to see if the left side of a player was blocking, for example, it would look something like this:

if (onwall2(player.x,player.y+1,1/16,2)==true) {
player.blockleft = true;
}
else {
player.blockleft = false;
}
a little bit of redundancy here.
onwall2(player.x,player.y+1,1/16,2)==true
true == true returns true
false == true returns false
so you can just do: if (onwall2(x,y,w,h))
otherwise it would be doing a double comparison, which should be avoided, although it really won't matter much unless you're doing a long for loop or something.
  #10  
Old 05-10-2006, 12:35 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
FIXED.
__________________
Deep into the Darkness peering...

Last edited by Angel_Light; 05-10-2006 at 12:56 AM..
  #11  
Old 05-10-2006, 02:12 AM
Shaun Shaun is offline
Registered User
Shaun's Avatar
Join Date: Jul 2003
Location: Canada
Posts: 1,070
Shaun is a jewel in the roughShaun is a jewel in the rough
When you have the benefit to, always listen to Massokre over me in scripting advice. I, for example, was unaware that it automatically interprets (the question) as a boolean (question).
  #12  
Old 05-10-2006, 01:44 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by jake13jake
onwater/onwater2 checks for lava and water tiles
onwall/onwall2 checks for anything that should be blocking according to the default system (includes players/npcs).

onwall(x,y) tells you if the specified coordinate is blocked
onwall2(x,y,w,h) tells you if there is anything blocking within the specified area
That is pretty much exactly what I said, except you tried to add the 'players/npcs' thing, but left something out. If it is a no playerkilling zone (or the noplayersonwall() function is called, players are not counted as blocking.)

Quote:
Originally Posted by jake13jake
a little bit of redundancy here.
onwall2(player.x,player.y+1,1/16,2)==true
true == true returns true
false == true returns false
so you can just do: if (onwall2(x,y,w,h))
otherwise it would be doing a double comparison, which should be avoided, although it really won't matter much unless you're doing a long for loop or something.
It's not redundancy. You are not doing double comparisons. That is the exact same thing as if you leave it out.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #13  
Old 05-10-2006, 02:32 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by ApothiX
That is pretty much exactly what I said, except you tried to add the 'players/npcs' thing, but left something out. If it is a no playerkilling zone (or the noplayersonwall() function is called, players are not counted as blocking.)


It's not redundancy. You are not doing double comparisons. That is the exact same thing as if you leave it out.
yea, noplayersonwall() will make players not detected by onwall.
while playersonwall() will reverse that.
using a no PK zone will imply noplayersonwall, but I haven't gone as far to see if calling playersonwall() would reverse that, and I don't use onwall anymore, but a function I scripted that detects tiletypes, npcs, and players on different cases.

And yea, it is redundancy.
You already get a return value of true, then you see if it is equal to true.
Otherwise you get a return value of false and you see if it is equal to true, and because false != true, it returns false. It doesn't really matter if you say ==true, but it's still redundant.
  #14  
Old 05-11-2006, 06:39 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
ok now for tiles. I know you can detect tiles with tiles[x,y] but how do I use this?
__________________
Deep into the Darkness peering...
  #15  
Old 05-12-2006, 12:04 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Angel_Light
ok now for tiles. I know you can detect tiles with tiles[x,y] but how do I use this?
It's just an array that stores values that represent different tiles. Doubt anyone's made a list of all the tile values. I think I've made an equation for it though (back when I made a gs1 tile editor script).

tilex + tiley * 16
reflects the position of the tile on the tileset image.

You don't need to use it unless you have a need to detect the different codes for tiles.
  #16  
Old 05-12-2006, 03:39 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
ok thx
__________________
Deep into the Darkness peering...
  #17  
Old 05-12-2006, 02:16 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by jake13jake
And yea, it is redundancy.
You already get a return value of true, then you see if it is equal to true.
Otherwise you get a return value of false and you see if it is equal to true, and because false != true, it returns false. It doesn't really matter if you say ==true, but it's still redundant.
Simply put: You are an idiot.

The client/server is going to do the == true check regardless if you put it or not. It does not do it twice if you put it. I will say it one more time: There is no redundancy in that statement.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #18  
Old 05-13-2006, 06:46 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by ApothiX
Simply put: You are an idiot.

The client/server is going to do the == true check regardless if you put it or not. It does not do it twice if you put it. I will say it one more time: There is no redundancy in that statement.
No, why would you make a statement true==true.

What if, for, and while statements do is interpret boolean values.

PHP Code:
//executes blah() always
if (true) {
  
blah();
}

//executes an infinite loop on blah();
while (true) {
  
blah();
}

//executes blah2(i) forever
for (i=0truei++) {
  
blah2(i);
}

//doesn't execute
if (false) {
  
blah();
}

//doesn't execute
while (false) {
  
blah();
}

//doesn't execute
for (i=0falsei++) {
  
blah2(i);

By putting (onwall(x,y) == true), you're comparing a boolean value to a boolean value, which isn't necessary. onwall(x,y) already returns true or false, and then you're comparing it to another boolean value. Putting (onwall(x,y) == true) would be the same thing as putting (onwall(x,y) && true), just not necessary. The only reason anyone should put ==true or ==false is if they believe that it would improve readability, and it usually has negative effects on the readability of the code.
  #19  
Old 05-13-2006, 07:15 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
Doodeedoo..

if (onwall() == true) is redundant. if (onwall()) is shorter and, in my opinion, easier to read.
However it doesn't really matter, so who cares?
  #20  
Old 05-14-2006, 01:07 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Yen
Doodeedoo..

if (onwall() == true) is redundant. if (onwall()) is shorter and, in my opinion, easier to read.
However it doesn't really matter, so who cares?
I think I've heard that before in this thread before okiesmokie went psycho on me, and although that seems to be a pattern, I'd rather have him realize I'm right and he's wrong because I enjoy lowering the pride of narcissists. What's the proud boy gonna argue now, eh?
  #21  
Old 05-14-2006, 05:36 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
PHP Code:
if (onwall() == true
PHP Code:
if (onwall()) 
Both are perfectly fine, I guess. Except one of them is like doing:
PHP Code:
if (true == true
Matter of preference, in my opinion.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
  #22  
Old 05-15-2006, 02:19 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
He is trying to say it's redundant to the interpreter, which it isn't. Even if you don't put ==true, THE INTERPRETER WILL STILL READ IT THE EXACT SAME. IF YOU PUT THE ==true, IT WILL NOT TRY TO ADD SOME RANDOM **** TO MAKE IT MORE PROCESSOR INTENSIVE. God. Learn to ****ing read.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #23  
Old 05-15-2006, 06:43 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by ApothiX
He is trying to say it's redundant to the interpreter, which it isn't. Even if you don't put ==true, THE INTERPRETER WILL STILL READ IT THE EXACT SAME. IF YOU PUT THE ==true, IT WILL NOT TRY TO ADD SOME RANDOM **** TO MAKE IT MORE PROCESSOR INTENSIVE. God. Learn to ****ing read.
well, only if it ignores the syntax. The boolean comparison is still there. I love how you're flipping out about this, it's not a big deal.
  #24  
Old 05-15-2006, 07:09 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by ApothiX
onwall and onwater check a single tile
Pixel. Not tile.
  #25  
Old 05-15-2006, 07:09 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by jake13jake
It's just an array that stores values that represent different tiles. Doubt anyone's made a list of all the tile values. I think I've made an equation for it though (back when I made a gs1 tile editor script).

tilex + tiley * 16
That is for the board array. The tiles[x,y] syntax is magical and does not require fancy maths, you just separate the coordinates with a comma.
  #26  
Old 05-15-2006, 07:14 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by ApothiX
He is trying to say it's redundant to the interpreter, which it isn't. Even if you don't put ==true, THE INTERPRETER WILL STILL READ IT THE EXACT SAME. IF YOU PUT THE ==true, IT WILL NOT TRY TO ADD SOME RANDOM **** TO MAKE IT MORE PROCESSOR INTENSIVE. God. Learn to ****ing read.
You are wrong. Stop violating the forum rules
  #27  
Old 05-15-2006, 08:40 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Loriel
That is for the board array. The tiles[x,y] syntax is magical and does not require fancy maths, you just separate the coordinates with a comma.
Yea, that just breaks every rule ever made for that operator, but stefan can break it because he's stefan.
  #28  
Old 05-17-2006, 01:35 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Wait so can some now explain to me tile[x,y]; is it like a array or somethin?
__________________
Deep into the Darkness peering...
  #29  
Old 05-17-2006, 10:53 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Angel_Light
Wait so can some now explain to me tile[x,y]; is it like a array or somethin?
It is like a function with [ ] instead of ( ) except you can assign to elements as if it was an array.
  #30  
Old 05-18-2006, 07:35 AM
Luigi203 Luigi203 is offline
Hamma Time
Luigi203's Avatar
Join Date: Mar 2003
Location: North East PA
Posts: 285
Luigi203 is on a distinguished road
Send a message via AIM to Luigi203
tiles[x,y] just gives you the tile index at x and y. Tilesets are broken up into 16 x 16 pixel 'tiles', and each tile has a unique index. This is just used to read and write these indecies. Experiment with it,

function OnMouseDown() {
player.chat = tiles[mousex,mousey];
}

to check tile indecies, and you can write them like so

function onMouseDown() {
tiles[mousex,mousey] = #;
}

Hope this helps..
__________________


CAUTION
  #31  
Old 05-18-2006, 07:58 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by ApothiX
He is trying to say it's redundant to the interpreter, which it isn't. Even if you don't put ==true, THE INTERPRETER WILL STILL READ IT THE EXACT SAME. IF YOU PUT THE ==true, IT WILL NOT TRY TO ADD SOME RANDOM **** TO MAKE IT MORE PROCESSOR INTENSIVE. God. Learn to ****ing read.
Breathe!

WOOOOOOOOOSAAAAHHH...
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
  #32  
Old 05-19-2006, 07:55 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by napo_p2p
Breathe!

WOOOOOOOOOSAAAAHHH...
Unless the compiler tries to trim it, it does make it more processor intensive, but only by a negligable amount. And the fact that the compiler would have to trim it would just make it more processor intensive at the time of compilation itself. But yea, I agree. Calm down, it's not like it really matters.
  #33  
Old 05-19-2006, 01:59 PM
Raeiphon Raeiphon is offline
I never asked for this.
Join Date: Jun 2005
Posts: 855
Raeiphon is on a distinguished road
Quote:
Originally Posted by Loriel
You are wrong. Stop violating the forum rules
Triple post, you fail. Stop violating the forum rules. Use the ****ing edit button.
__________________

I hope for nothing. I fear nothing. I am free.
  #34  
Old 05-19-2006, 02:17 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Raeiphon
Triple post, you fail. Stop violating the forum rules. Use the ****ing edit button.
Read the forum rules. He is using hybrid mode.

Also, I am not wrong about the == true thing.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #35  
Old 05-19-2006, 08:04 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by ApothiX
Read the forum rules. He is using hybrid mode.

Also, I am not wrong about the == true thing.
Tell me, why would you write
if( (x==2) || (x==3) || (x==5) || (x==7) )

When you could write

if( (1<<x) & ((1<<2)|(1<<3)|(1<<5)|(1<<7) )

I'll tell you what though, I've only been recently learning how to use bitwise operators.
  #36  
Old 05-21-2006, 10:53 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by ApothiX
Also, I am not wrong about the == true thing.
Then why stop there instead of doing if ((foo() == true) == true)?
  #37  
Old 05-21-2006, 11:01 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by jake13jake
Tell me, why would you write
if( (x==2) || (x==3) || (x==5) || (x==7) )

When you could write

if( (1<<x) & ((1<<2)|(1<<3)|(1<<5)|(1<<7) )

I'll tell you what though, I've only been recently learning how to use bitwise operators.
If you are using the new engine...
NPC Code:
if (x in {1, 2, 3, 5, 7})

__________________
Skyld
  #38  
Old 05-21-2006, 05:36 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Skyld
If you are using the new engine...
NPC Code:
if (x in {1, 2, 3, 5, 7})

I know
you can also do things like

NPC Code:
if ( (x|y) in |22,42| )



Actually, couldn't you have done that in the old engine too (the former)?

However, let's say you have
NPC Code:
 if ( x in arr ) 


I've had a problem in which my array has to contain multiple values. It can't just contain one value. In my movement functions there's generally multiple parameters in the array, but what if you wanted only one value in the array? I've had to use switch (arr.type()) to cope with the language not being very great with array sizes of 1. Of course it's not really an array if it only has one value, but the fact that it's usually an array, it might make it good to have the in operator behave like == when the right operand contains a single value for better dynamic behavior.

Last edited by jake13jake; 05-21-2006 at 05:47 PM..
  #39  
Old 05-24-2006, 02:21 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by jake13jake
Tell me, why would you write
if( (x==2) || (x==3) || (x==5) || (x==7) )

When you could write

if( (1<<x) & ((1<<2)|(1<<3)|(1<<5)|(1<<7) )

I'll tell you what though, I've only been recently learning how to use bitwise operators.
Because the compiler would interpret those as bitwise operators. if(function()) is doing an '== true' check, if(function() == true) is NOT doing two checks for true. If you honestly think I am wrong in this, then you would think that if(function() == false) is doing a check for both true and false.

Read my damn text before you reply. I am done with this thread.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #40  
Old 05-24-2006, 06:19 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by ApothiX
Because the compiler would interpret those as bitwise operators. if(function()) is doing an '== true' check, if(function() == true) is NOT doing two checks for true. If you honestly think I am wrong in this, then you would think that if(function() == false) is doing a check for both true and false.

Read my damn text before you reply. I am done with this thread.
if (function() == false)

CASE 1:
function() returns true
true == false
true is not equivalent to false, therefore the statement is false.

CASE 2:
function() returns false
false == false
false is equivalent to false, therefore the statement is true.

Tell me, what's the contrapositive to p->q?

Seriously, take a course in logic or something.

Last edited by jake13jake; 05-24-2006 at 06:32 PM..
Closed Thread


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:52 AM.


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