![]() |
onwall and such
can someone thuroghly explain onwall,onwall2, onwater, and things of the such. Please. The wiki doesnt help much for me.
|
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.
|
Quote:
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 |
ok thanks, I got it BUT, with onwall2 is it possible to just detect a blocking tile without specific coordinates? like this.x???
|
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.
|
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. |
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; } |
oh I see. Thank you much. ^.^
EDIT: Okay, it work on all walls but down and right... ? |
Quote:
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. |
FIXED.
|
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).
|
Quote:
Quote:
|
Quote:
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. |
ok now for tiles. I know you can detect tiles with tiles[x,y] but how do I use this?
|
Quote:
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. |
ok thx
|
Quote:
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. |
Quote:
What if, for, and while statements do is interpret boolean values. PHP Code:
|
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? |
Quote:
|
PHP Code:
PHP Code:
PHP Code:
|
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.
|
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Wait so can some now explain to me tile[x,y]; is it like a array or somethin?
|
Quote:
|
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.. |
Quote:
WOOOOOOOOOSAAAAHHH... |
Quote:
|
Quote:
|
Quote:
Also, I am not wrong about the == true thing. |
Quote:
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. |
Quote:
|
Quote:
NPC Code: |
Quote:
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. |
Quote:
Read my damn text before you reply. I am done with this thread. |
Quote:
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.