jumping tutorial?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
OK, but the variable name is confusing me... The left object on the Y axis?
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: jumping tutorial?
I think he problem is here (in red for improved dramatic effect):
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
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.toaster468 wrote:This is in love:load()used to get the tile to the left of the player.Code: Select all
Line 68: leftTileX, leftTileY = tile_X - 1, tile_Y
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)
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.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
Sorry, I have a very object oriented background in programming and I by nature define all of the variables before hand.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
OK it compiles, but I cannot move. I'm going to try and see whats wrong.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
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
Code: Select all
tile_X, tile_Y = (map_w - player_X)/2, (map_h - player_Y)/2
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
Yeah, I think I found the problem: I was dividing my 2 instead of 32 to find the tile I was in
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
Still nothing
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
I'll try tomorrow, as my saying goes:
Restful eyes offer more insight!
Restful eyes offer more insight!
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: jumping tutorial?
Ok this is what you need to do. You need to change this:
To this:
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.
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
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
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.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
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.
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.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests