Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   onwall and such (https://forums.graalonline.com/forums/showthread.php?t=65923)

Angel_Light 05-08-2006 10:03 PM

onwall and such
 
can someone thuroghly explain onwall,onwall2, onwater, and things of the such. Please. The wiki doesnt help much for me.

ApothiX 05-09-2006 02:06 PM

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.

jake13jake 05-09-2006 05:45 PM

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

Angel_Light 05-09-2006 10:28 PM

ok thanks, I got it BUT, with onwall2 is it possible to just detect a blocking tile without specific coordinates? like this.x???

Shaun 05-09-2006 10:41 PM

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.

Angel_Light 05-09-2006 10:59 PM

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.

Shaun 05-09-2006 11:05 PM

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;
}

Angel_Light 05-09-2006 11:06 PM

oh I see. Thank you much. ^.^

EDIT: Okay, it work on all walls but down and right... ?

jake13jake 05-10-2006 12:01 AM

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.

Angel_Light 05-10-2006 12:35 AM

FIXED.

Shaun 05-10-2006 02:12 AM

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).

ApothiX 05-10-2006 01:44 PM

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.

jake13jake 05-10-2006 02:32 PM

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.

Angel_Light 05-11-2006 06:39 AM

ok now for tiles. I know you can detect tiles with tiles[x,y] but how do I use this?

jake13jake 05-12-2006 12:04 AM

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.

Angel_Light 05-12-2006 03:39 AM

ok thx

ApothiX 05-12-2006 02:16 PM

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.

jake13jake 05-13-2006 06:46 PM

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.

Yen 05-13-2006 07:15 PM

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?

jake13jake 05-14-2006 01:07 AM

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?

napo_p2p 05-14-2006 05:36 AM

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.

ApothiX 05-15-2006 02:19 PM

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.

jake13jake 05-15-2006 06:43 PM

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.

Loriel 05-15-2006 07:09 PM

Quote:

Originally Posted by ApothiX
onwall and onwater check a single tile

Pixel. Not tile.

Loriel 05-15-2006 07:09 PM

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.

Loriel 05-15-2006 07:14 PM

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

jake13jake 05-15-2006 08:40 PM

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.

Angel_Light 05-17-2006 01:35 PM

Wait so can some now explain to me tile[x,y]; is it like a array or somethin?

Loriel 05-17-2006 10:53 PM

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.

Luigi203 05-18-2006 07:35 AM

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..

napo_p2p 05-18-2006 07:58 AM

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...

jake13jake 05-19-2006 07:55 AM

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. :frown: But yea, I agree. Calm down, it's not like it really matters.

Raeiphon 05-19-2006 01:59 PM

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.

ApothiX 05-19-2006 02:17 PM

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.

jake13jake 05-19-2006 08:04 PM

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.

Loriel 05-21-2006 10:53 AM

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)?

Skyld 05-21-2006 11:01 AM

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})


jake13jake 05-21-2006 05:36 PM

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.

ApothiX 05-24-2006 02:21 PM

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.

jake13jake 05-24-2006 06:19 PM

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.


All times are GMT +2. The time now is 12:36 AM.

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