I don't understand classes
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
I don't understand classes
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 ><
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: I don't understand classes
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.
Re: I don't understand classes
Try not to cringe at the code, lolRobin 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.
- Attachments
-
- Asteroid.love
- (790 Bytes) Downloaded 80 times
Re: I don't understand classes
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!
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!
https://github.com/Sulunia
Re: I don't understand classes
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.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!
Re: I don't understand classes
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.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.
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.
Re: I don't understand classes
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!MadByte wrote: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.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.
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.
Re: I don't understand classes
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!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!
- Le_juiceBOX
- Citizen
- Posts: 71
- Joined: Sat Mar 26, 2016 3:07 pm
Re: I don't understand classes
trolololol. Sorry but whats wrong with you? Two non-sense threads and posts likes this one.Le_juiceBOX wrote:--
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.).
Who is online
Users browsing this forum: Ahrefs [Bot] and 4 guests