Having trouble with code

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
ZBoyer1000
Prole
Posts: 39
Joined: Sat Nov 28, 2015 10:13 am

Having trouble with code

Post by ZBoyer1000 »

I have been following a tutorial on developing a game on Love 0.8.0 for a couple of days, but I am having trouble getting it to work properly.
I don't know if the code has been changed for Love 0.10.0. Can anybody be able to please help me with this? :?

https://www.mediafire.com/?zc1733wbchs0d8q
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Having trouble with code

Post by zorg »

Other than the fact that you don't seem to call p:draw() in love.draw, i see only two additional issues.

First, you should make the Player table local, and return it at the end of the file, so you don't declare globals all over the place, like so:

Code: Select all

-- in player.lua
local Player = {}
...
return Player
Then, in main.lua, you could require player.lua to its own local.

Code: Select all

-- in main.lua
local Player = require 'player'
This keeps code clean, since you can actually see what you required where, and into what, though this is more of a suggestion than a necessity.

The other, bigger issue is that in player.lua's update and draw methods, you're using colon (:) syntax, which passes the object as the parameter called self, not p that you use everywhere. Either replace p.everything with self.everything in those two functions (not in new), or instead of Player:update(dt) and Player:draw(), use Player.update(p, dt) and Player.draw(p).

Also, 0.8.x tutorials will probably be outdated in aspects regarding löve itself, so do consult with the wiki often.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests