Looping problem

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Looping problem

Post by davisdude »

I'm encountering a problem with an attempt at a* movement.
If you don't know what that is, it is computer influenced movement/path-finding. Right now all I have is the basics.
The brown things are obstacles. I'm going to change my code to avoid obstacles once I get it to work without obstacles.
It's only supposed to move one at a time, but instead it moves, usually, around four at a time, towards the yellow block.
You have to press a key to activate the movement.
I anybody could look at what I'm doing wrong that would be greatly appreciated! :awesome:
Attachments
a_star.love
(2.66 KiB) Downloaded 67 times
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
severedskullz
Prole
Posts: 36
Joined: Thu May 30, 2013 1:55 am

Re: Looping problem

Post by severedskullz »

In line 46 of Main.lua you are breaking the loop and allowing more executions. You're naming conventions are horrible, so I don't know what variable is what. I assume you want to 'return' there instead, which solved your issue.

After the 4th iteration I ran into an error on line 84 in tile.lua in which you are trying to access nil values by blindly accessing indexes of a table. In this case, you are at the bottom with no tiles below you, yet you try and access a non-existent tile. You need to check and see if the exist first before you assign them and use them in expressions.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Looping problem

Post by davisdude »

Thanks! This solved my problem! :awesome:
Still can't figure out what's wrong with that scenario, though, since I create the tables if it's not there. :P
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
severedskullz
Prole
Posts: 36
Joined: Thu May 30, 2013 1:55 am

Re: Looping problem

Post by severedskullz »

davisdude wrote:Thanks! This solved my problem! :awesome:
Still can't figure out what's wrong with that scenario, though, since I create the tables if it's not there. :P
Why? That's a very bad way of going about a solution. You need to check if there is tiles on all 4 sides before you try and use it in your formula. If there isn't anything below you obviously you cannot go down, so don't take it into consideration when you are weighing the least expensive path for A*.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Looping problem

Post by davisdude »

Yeah, I know. It just keeps my code DRY.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests