jumping tutorial?

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.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

OK, but the variable name is confusing me... The left object on the Y axis?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: jumping tutorial?

Post by kikito »

I think he problem is here (in red for improved dramatic effect):
toaster468 wrote:This is in love:load()

Code: Select all

Line 68: leftTileX, leftTileY = tile_X - 1, tile_Y
used to get the tile to the left of the player.

Code: Select all

Line 69: leftTileNo = map[leftTileY][leftTileX] -- will return 0,1,2,3 etc (remember, 'y' goes first when using the map variable)
Toaster, those lines have to be just before the player position is changed. In your case, that is in love.keypress. Not in love.load.

I think that what happens is that you are trying to use leftTileNo inside love.keypress, but you are defining it inside love.load.

Try moving all he new code to the beginning of love.keypress
When I write def I mean function.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

Sorry, I have a very object oriented background in programming and I by nature define all of the variables before hand.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

OK it compiles, but I cannot move. I'm going to try and see whats wrong.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

Code: Select all

if love.keyboard.isDown( "left" ) and leftTileNo == 0 then
	leftTileX, leftTileY = tile_X - 1, tile_Y
	leftTileNo = map[leftTileY][leftTileX]
	player_X = player_X - 1
	player_direction = "l"

	end
end
I think the problem lies here and in

Code: Select all

tile_X, tile_Y = (map_w - player_X)/2, (map_h - player_Y)/2
The last equation may be giving the top one wrong info.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

Yeah, I think I found the problem: I was dividing my 2 instead of 32 to find the tile I was in :ehem:
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

Still nothing :(
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

I'll try tomorrow, as my saying goes:

Restful eyes offer more insight!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: jumping tutorial?

Post by kikito »

Ok this is what you need to do. You need to change this:

Code: Select all

if love.keyboard.isDown( "left" ) and leftTileNo == 0 then
   leftTileX, leftTileY = tile_X - 1, tile_Y
   leftTileNo = map[leftTileY][leftTileX]
   player_X = player_X - 1
   player_direction = "l"
end
To this:

Code: Select all

local leftTileX, leftTileY = tile_X - 1, tile_Y
local leftTileNo = map[leftTileY][leftTileX]
if love.keyboard.isDown( "left" ) and leftTileNo == 0 then
   player_X = player_X - 1
   player_direction = "l"
end
A very basic programming principle is: don't use a variable before you define its value. In your code, the 'if' is using leftTileNo before it is defined.

It's my fault, I guess. I told you to put the left calculations "right before the player position is updated". From now on, assume that the rule "don't use a variable if you have not defined it before" overrides other rules (there are some cases in which it doesn't apply, but you are still too inexperienced to know about those)

The 'local' is there so leftTileX, leftTileY and leftTileNo aren't 'visible' outside love.keypress. This is a good thing because later on you might want to use those names for other variables in other functions (for example, if you want to make enemies move). Making them local makes sure that those other functions will not inadvertedly modify the values of the variables on this function.
When I write def I mean function.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

OK, good and bad news.

good news: It compiles and I can move.

bad news: It is not stopping my character after it meets a block with the code "1" in the map table.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests