- Joined
- Oct 18, 2007
- Messages
- 930
Tutorial: Check If Point Is Walkable
For this you will need:
The system im going to teach you is a simple system that allows you to check if the point is blocked by a wall, tree or doodad. ( This is more accurate than the IsTerrainPathable )
I recommend to use this simple func because of it's accuracy.
Final Note
For this you will need:
- The latest version of JNGP, can be found here
- Jass and vJass knowledge
The system im going to teach you is a simple system that allows you to check if the point is blocked by a wall, tree or doodad. ( This is more accurate than the IsTerrainPathable )
I recommend to use this simple func because of it's accuracy.
CheckSystem GuideFirst thing you are going to is to open your converted trigger and create a library, lets call it CheckSystem
JASS:library CheckSystem initializer Init endlibrary
Now for the globals:
JASS:library CheckSystem initializer Init globals // This item id 'sehr' is just a random item id, // you can use whatever you want private constant integer I_ID = 'sehr' private item I = null endglobals endlibrary
When the globals are done the rest is pretty easy to do. First, we are going to add the "Init" function that we declared in the library's initializer
JASS:library CheckSystem initializer Init globals private constant integer I_ID = 'sehr' private item I = null endglobals private function Init takes nothing returns nothing // Creating the item set I = CreateItem(I_ID, 0, 0) // We turn off the visibility for the item because we dont // want it to show up in game. call SetItemVisible(I, false) endfunction endlibrary
Now for the final function in this system. This is the function you will be calling to check that the point is walkable. Lets call the function "IsPointWalkable".NoteWe made a private function because we dont want it to be shared with other systems
JASS:library CheckSystem initializer Init globals private constant integer I_ID = 'sehr' private item I = null endglobals function IsPointWalkable takes real x, real y returns boolean // What we do is that we set the item to the point that is given. // Then we check if the item's position after moving is what it // should be. call SetItemPosition(I, x, y) // We set the item's visible off again because it is turned // on whenever it is moved call SetItemVisible(I, false) return GetItemX(I) == x and GetItemY(I) == y endfunction private function Init takes nothing returns nothing set I = CreateItem(I_ID, 0, 0) call SetItemVisible(I, false) endfunction endlibrary
NoteRemmember to always use "function" or "public function" for usage outside the library/scope. A "private function" cannot be accessed outside the system
The final code:
JASS:library CheckSystem initializer Init globals // This item id 'sehr' is just a random item id, // you can use whatever you want private constant integer I_ID = 'sehr' private item I = null endglobals function IsPointWalkable takes real x, real y returns boolean // What we do is that we set the item to the point that is given. // Then we check if the item's position after moving is what it // should be. call SetItemPosition(I, x, y) // We set the item's visible off again because it is turned // on whenever it is moved call SetItemVisible(I, false) return GetItemX(I) == x and GetItemY(I) == y endfunction private function Init takes nothing returns nothing // Creating the Item set I = CreateItem(I_ID, 0, 0) // We turn off the visibility for the item because we dont // want it to show up in game. call SetItemVisible(I, false) endfunction endlibrary
NoteThis system is really easy to use.
Example:
JASS:function Test takes nothing returns nothing local real x = 47 local real y = 19 if IsPointWalkable(x, y) then call BJDebugMsg("Point is walkable!") endif endfunction
This sytem only applies for doodads, destructables and buildings( Things that normal land units cannot walk on )
Last edited: