• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Check If Point Is Walkable

Level 18
Joined
Oct 18, 2007
Messages
930
Tutorial: Check If Point Is Walkable

For this you will need:
  1. The latest version of JNGP, can be found here
  2. 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 Guide
First 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
Note
We made a private function because we dont want it to be shared with other systems
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".
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
Note
Remmember 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
Note
This 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
Final Note
This sytem only applies for doodads, destructables and buildings( Things that normal land units cannot walk on )
 
Last edited:
Level 24
Joined
Feb 28, 2007
Messages
3,479
I agree with what Poot said above. Since I'm not a JASSer I can't tell whatever this works at all or not. But what I can say is that you are telling people how to do something, not how it works etc. A real tutorial should be about explaining and teaching something to someone, instead of just giving them an already finished code. For that, they could just go to the JASS resource section. My suggestion is to add some more explanations to what the different steps and the code in them actually mean.
 
Top