I don't understand classes

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
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

I don't understand classes

Post by Vimm »

for as long as I've been studying programming (on and off for a few years) I've never understood how classes work and how to "call them" or whatever, like if I make an enemy class and try to add it to main, i always get some kind of error and just dont understand, which is why ive never made it far in programming, it confuses me and i get frustrated, and end up quitting . Can someone help me? I dont want to quit this time but I cant comprehend classes :/ I've watched tutorials and the such, and yeah i can get the tutorials code to work, but I dont understand why it works ><
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: I don't understand classes

Post by Robin »

Okay, so could you upload a recent attempt of yours to use classes? Then we can walk you through it step by step. If you help us help you, I promise it won't be hard.
Help us help you: attach a .love.
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: I don't understand classes

Post by Vimm »

Robin wrote:Okay, so could you upload a recent attempt of yours to use classes? Then we can walk you through it step by step. If you help us help you, I promise it won't be hard.
Try not to cringe at the code, lol
Attachments
Asteroid.love
(790 Bytes) Downloaded 73 times
User avatar
Sulunia
Party member
Posts: 203
Joined: Tue Mar 22, 2016 1:10 pm
Location: SRS, Brazil

Re: I don't understand classes

Post by Sulunia »

So, i took a look at your project, and i noticed right off the bat you're trying to call Asteroid.new(). Unfortunately, Lua in itself is not object oriented (correct me if i'm wrong) but that can be implemented. So, do you want to do object orienting yourself (code the constructors and stuff) or just be able to use objects in your game?

If the latter, then you could just use an object orienting lib for lua. There are a few options, every single one of them pulls off the job graciously without any complications or such.
You can grab one for yourself here:https://github.com/love2d-community/awe ... rientation

If you want to make your own OO engine, then wait until someone with that knowledge pops here. I'm fairly new to Lua, hence the reason i can't really help out. Best of luck though!
Don't check my github! It contains thousands of lines of spaghetti code in many different languages cool software! :neko:
https://github.com/Sulunia
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: I don't understand classes

Post by Vimm »

Sulunia wrote:So, i took a look at your project, and i noticed right off the bat you're trying to call Asteroid.new(). Unfortunately, Lua in itself is not object oriented (correct me if i'm wrong) but that can be implemented. So, do you want to do object orienting yourself (code the constructors and stuff) or just be able to use objects in your game?

If the latter, then you could just use an object orienting lib for lua. There are a few options, every single one of them pulls off the job graciously without any complications or such.
You can grab one for yourself here:https://github.com/love2d-community/awe ... rientation

If you want to make your own OO engine, then wait until someone with that knowledge pops here. I'm fairly new to Lua, hence the reason i can't really help out. Best of luck though!
Ohh, see I've heard that you should use libraries like "classis" for objects, but every resource I saw made it sound optional, didn't know lua wasnt OO.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: I don't understand classes

Post by MadByte »

Vimm wrote: Ohh, see I've heard that you should use libraries like "classis" for objects, but every resource I saw made it sound optional, didn't know lua wasnt OO.
They are in fact optional if you don't want to think about how to use tables and metatables to create classes and inheritance in lua.
Personally I started by looking at the Lua pil to find out how to use metatables to create classes.
As you can see it is pretty straight forward.

Also if you look at "classic.lua" you'll see that it's functionality is created in just a few well crafted lines of code - its not rocket science.
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: I don't understand classes

Post by Vimm »

MadByte wrote:
Vimm wrote: Ohh, see I've heard that you should use libraries like "classis" for objects, but every resource I saw made it sound optional, didn't know lua wasnt OO.
They are in fact optional if you don't want to think about how to use tables and metatables to create classes and inheritance in lua.
Personally I started by looking at the Lua pil to find out how to use metatables to create classes.
As you can see it is pretty straight forward.

Also if you look at "classic.lua" you'll see that it's functionality is created in just a few well crafted lines of code - its not rocket science.
Oh nice, I'll bookmark that link to read when im more..awake XD and yeah i looked at classics code, it doesnt look so hard, im sure id understand it if i knew i tiny bit more haha. Thanks!
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: I don't understand classes

Post by Vimm »

Sulunia wrote:So, i took a look at your project, and i noticed right off the bat you're trying to call Asteroid.new(). Unfortunately, Lua in itself is not object oriented (correct me if i'm wrong) but that can be implemented. So, do you want to do object orienting yourself (code the constructors and stuff) or just be able to use objects in your game?

If the latter, then you could just use an object orienting lib for lua. There are a few options, every single one of them pulls off the job graciously without any complications or such.
You can grab one for yourself here:https://github.com/love2d-community/awe ... rientation

If you want to make your own OO engine, then wait until someone with that knowledge pops here. I'm fairly new to Lua, hence the reason i can't really help out. Best of luck though!
Also, after implementing classic and looking at some references to see how to make it work, I got it to work! I still got a long way to go to fully understand classes, but this is still the farthest I've gotten, thanks for helping!
User avatar
Le_juiceBOX
Citizen
Posts: 71
Joined: Sat Mar 26, 2016 3:07 pm

Re: I don't understand classes

Post by Le_juiceBOX »

--
SteamLibrary-like Program For Love2D Games:
take me to the forum thread!
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: I don't understand classes

Post by MadByte »

Le_juiceBOX wrote:--
trolololol. Sorry but whats wrong with you? Two non-sense threads and posts likes this one.
I suggest you to write in whole sentences. Also try to use the bbcode "Code" functionality and research stuff via google or the forum search function before posting anything.
If you got any questions regarding how to use the forum take a look here and here.
Also pay attention to our forum etiquette (especially nr. 3. / 4. and 9.).
Post Reply

Who is online

Users browsing this forum: No registered users and 76 guests