Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to call method 'getX' (a nil value) #35

Closed
ghost opened this issue Sep 27, 2014 · 6 comments
Closed

Attempt to call method 'getX' (a nil value) #35

ghost opened this issue Sep 27, 2014 · 6 comments
Labels

Comments

@ghost
Copy link

ghost commented Sep 27, 2014

Hi, sorry if this is the wrong place to ask for help; I couldn't find a forum to post to. Thanks for the amazing library you built together! I'm working on implementing it in Dota 2 modding. I have a couple questions.

1: The program is finding a path, but when it tries to execute this line:

         print(('Step: %d - x: %d - y: %d'):format(count, node:getX(), node:getY())) 

it gives me an error: "attempt to call method 'getX' (a nil value)".

When I comment out that line and let the for loop run, here is each node's table printed out: http://pastebin.com/wUTbn3NN

2: What are you required to do when you need to change nodes from walkable to unwalkable and vice versa? At the moment I'm changing values in the collision map to 1 (without searching), and then running this code:

    -- Library setup
    local Grid = require ("jumper/grid") -- The grid class
    local Pathfinder = require ("jumper/pathfinder") -- The pathfinder lass

    -- Creates a grid object
    local grid = Grid(MAP) 
    -- Creates a pathfinder object using Jump Point Search
    local myFinder = Pathfinder(grid, 'JPS', walkable)

However this seems quite expensive, and I even get small lag spikes everytime this executes.

Thanks!

@ghost
Copy link
Author

ghost commented Sep 28, 2014

Ok, I figured out the first problem. I had to use node.x and node.y instead of node.getX() and node.getY(). Is the readme outdated? :O

@pancinteractive
Copy link

Remember to use the most recent stable build of Jumper and not the dev version.

@Yonaba
Copy link
Owner

Yonaba commented Sep 28, 2014

@Myll, first of all, thanks for the kind words, and for your interest.

Concerning the first question, well, the README is not outdated. You are actually (I believe) using the newer syntax for the actual development version of this library, as @pancsoftware kindly pointed out. Instead, use the latest stable version (which is 1.8.1, at the moment, and the example given for this version.).
I will manage to find some time and reorganise the repository, and leave the latest stable accessible from the main branch. As-is, I admit the repository layout is quite messy. Sorry for that.

As for the second question, you normally don't need to do such expensive things. Actually, Jumper resolves the collision map dynamically. You just have to init a pathfinder once, passing it your collision map. Later on, if you need to change node from walkable to unwalkable, or vice versa, just tweak the collision map data directly. For instance:

local map = {
  {0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0},
}

local Grid = require ('jumper.grid')
local Pathfinder = require ('jumper.pathfinder')

local walkable = 0
local myGrid = Grid(map)
local myFinder = Pathfinder(grid, 'ASTAR',walkable)

-- Need to change node at (x = 4,y = 1) behaviour
print(myGrid:isWalkableAt(4,1)) --> true

map[1][4] = 1 -- Change the collision map data for node(4,1) from "0" to "1"
print(myGrid:isWalkableAt(4,1)) --> false

This is basically how it works. By changing the underlying collision map data, in case a value on this map no longer matches the initial "walkable" property given, Jumper considers the corresponding node as no longer walkable.

PS/ Side note, it is advised in general not to use "/" in paths passed to require, but instead use dots ".". Slashes can cause problems on some specific systems, while dots will not. So better use this style:

local Grid = require ("jumper.grid") -- The grid class
local Pathfinder = require ("jumper.pathfinder") -- The pathfinder lass

You might have noticed this is the style I always use in the examples I give in all my READMEs.

Hope all of this helps. Let me know how it goes anyway.

@Yonaba Yonaba added question and removed question labels Sep 28, 2014
@ghost
Copy link
Author

ghost commented Sep 28, 2014

Hi Yonaba,

Yes, I was using the stable version but was referring to the newer syntax. Also, I had to change the dots to slashes because it was giving me errors like these:

[ VScript ]: [X] module jumper/core/path FAILED: scripts/vscripts/jumper/core/path.lua:18: loop or previous error loading module 'jumper/core/path' [ VScript ]: [X] module jumper/grid FAILED: scripts/vscripts/jumper/grid.lua:41: module 'jumper/grid.core.node' not found: [ VScript ]: no field package.preload['jumper/grid.core.node']Failed to find scripts/vscripts/jumper/grid/core/node.lua

The library is working nicely, but I have a question regarding tunneling. I understand the stable version doesn't support tunneling with JPS, but what about ASTAR?

When I use ASTAR and set tunneling to false (I also tried true):
local path, length = MyFinder:getPath(startx, starty, endx, endy, false)

I still get a path like this. I added purple rectangles where I believe extra nodes should be.
Image

Thank you!

@ghost ghost closed this as completed Oct 22, 2014
@Yonaba
Copy link
Owner

Yonaba commented Oct 23, 2014

Hi @Myll,
Sorry for the delay. I see what the problem is. You just need something i'll rather call it "corner crossing". This feature is not availale as-of-now, but will be implemented later. I already filed an issue for this a while back (see #30 for more details). For now, if the original problem is solved, we can keep this issue closed, and watch what goes on with issue #30.
Thanks.

@ghost
Copy link
Author

ghost commented Oct 23, 2014

Got it, thanks.

On Oct 23, 2014, at 7:26 AM, Roland Y. notifications@github.com wrote:

Hi @Myll https://github.com/Myll,
Sorry for the delay. I see what the problem is. You just need something i'll rather call it "corner crossing". This feature is not availale as-of-now, but will be implemented later. I already filed an issue for this a while back (see #30 #30 for more details). For now, if the original problem is solved, we can keep this issue closed, and watch what goes on with issue #30 #30.
Thanks.


Reply to this email directly or view it on GitHub #35 (comment).

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants