Some code to correct

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
Sosolol261
Party member
Posts: 125
Joined: Wed Nov 26, 2014 6:43 am

Some code to correct

Post by Sosolol261 »

Hello guys!

I am making a game wow who could have guessed?
So in my code, I can't enter a place(Town, Dungeon, or else) after I left it.

Didn't comment the project.
Ask if you want it commented.

Thanks! :awesome:

P.S. I just started this game which means: no textures, sounds, content, e.t.c
rexjericho
Prole
Posts: 44
Joined: Sat Dec 15, 2012 7:55 am

Re: Some code to correct

Post by rexjericho »

Hey, I had a look at your code. You should try printing debug information for both player.mpos and player.ppos to see what is going on.

It looks like player.ppos is only being updated when your guy is inside a dungeon. And it looks like the location changes back to "map" when your player's ppos position goes out of bounds. So this is what I think is happening:

1. your players ppos goes out of bounds and exits dungeon, and location changes to "map"
2. your player goes back to a location and you press "return"
3. the location gets changed to the dungeon name
4. map_border() function is called and checks ppos. Since ppos is still out of bounds, the location is set back to "map"

Suggestion for fix: When your player enters a dungeon in the place_enter() function, set the player.ppos position to something that is inside the bounds of the location. I notice that when you enter a location, you set the variable called "player.pos". Could this be a typo and you mean to set player.ppos instead?

Also, when asking for help on a bug, it would be handy to have a little more information about what the problem is. Such as a step by step guide to reproduce the problem, what is expected to happen, what actually happened. Example:

1. move player to green square location
2. press return to enter location
3. move player out of window to exit location
4. move player to green square location
5. press return to enter location

What is expected to happen? Player enters a location.
What actually happened? Player does not enter a location and nothing happens

Hope this helps. Good luck with your game!
Sosolol261
Party member
Posts: 125
Joined: Wed Nov 26, 2014 6:43 am

Re: Some code to correct

Post by Sosolol261 »

Yes it was the simple pos to ppos typo :D

Thanks for your help appreciate it!!!
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: Some code to correct

Post by Jeeper »

Sosolol261 wrote:Yes it was the simple pos to ppos typo :D

Thanks for your help appreciate it!!!
A tip to avoid future mistakes like that (or at least helps against it) is to avoid using abbreviations, sure they might make sense to you right now, but in a huge project it is easy to forget what "ppos" means. I always type out my variables and keep them stored in tables, an example is "player.currentPosition.x", reading that variable allows you to instantly know what it is, and with features like autofill on Sublime, it does not even slow you down. This also allows you to not need any commenting (for most part).
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests