C++ programmer going into LOVE
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
C++ programmer going into LOVE
I really have hard time getting into LOVE, I have never done any scripting. Are there classes, inheritance? what about mainloops for game? I'm a bit confused.
Re: C++ programmer going into LOVE
The source code of engine is very complicated, I had to choose another engine to be modified. But LUA language and LOVE API are very simple, try to download tutorials.
Re: C++ programmer going into LOVE
Lua is not only a scripting language, but a full programming language as well. Coming from C++ a few of the nice changes are no need to declare variable types or sizes, and Lua's famous table data structure. A table is something akin to a dynamically resizable array that can hold numbers, strings, functions, other tables... the list goes on. Lua also has an excellent garbage collector to manage memory for you.
Everyone here will point you here to get started: http://www.lua.org/pil/
It is one of the best resources for learning the language.
Also if you are interested in OOP: http://www.lua.org/pil/13.html
Lua metatables can be used to create an OOP type environment. This is more advanced stuff you can play with once you get a grasp on the language.
The first thing I can recommend you to do after learning syntax is to learn how to use Tables. They are one of the greatest things that sets Lua apart from other languages!
Everyone here will point you here to get started: http://www.lua.org/pil/
It is one of the best resources for learning the language.
Also if you are interested in OOP: http://www.lua.org/pil/13.html
Lua metatables can be used to create an OOP type environment. This is more advanced stuff you can play with once you get a grasp on the language.
The first thing I can recommend you to do after learning syntax is to learn how to use Tables. They are one of the greatest things that sets Lua apart from other languages!
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: C++ programmer going into LOVE
As for the game main loop see love.run. Also note that you rarely need to redefine it yourself.
Help us help you: attach a .love.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: C++ programmer going into LOVE
There is a main loop (love.run) in LÖVE, but most of the time (specially when you are learning) you don't need to use it. Instead there are three functions: love.load() for loading initial resources (i.e. images, etc), love.update(dt) for updating variables (moving characters, adding new ones, etc) and love.draw() to draw them.Cl4d wrote:I really have hard time getting into LOVE, I have never done any scripting. What about mainloops for game? I'm a bit confused.
LÖVE is scripted in the Lua language. Lua isn't Object-oriented. If you are familiar with Javascript, it's similar in some aspects.Cl4d wrote:Are there classes, inheritance?
Nevertheless, there are lots of people (me among them) doing Object Oriented libraries on top of the "basic structure" provided by Lua (just like there are some OOP libraries for Javascript, too).
On the Libraries section in the wiki there are at least two: my library, MiddleClass and also SECS
Last edited by kikito on Thu Jul 07, 2011 8:37 pm, edited 1 time in total.
When I write def I mean function.
Re: C++ programmer going into LOVE
As it has already been pointed out, Lua does not have real object orientation built in. It comes very close if you master metatables, though. As a matter of fact, after just a few weeks of Lua, I find metatables to be very useful and flexible. Before Lua, I mainly wrote Java so programming without OO is unthinkable for me, yet metatables provide pretty much everything you need.
There are lots of guides and stuff, but I thought I'd write a simple "class" to you just to show how it's done with metatables.
There are lots of guides and stuff, but I thought I'd write a simple "class" to you just to show how it's done with metatables.
Code: Select all
example={}
example.attribute = 4
function example:method()
self.attribute = self.attribute + 1
end
function newExampleObject()
newObject = {}
setmetatable(newObject,example)
example.__index=example
return newObject
end
obj = newExampleObject()
obj:method()
obj:method()
print(obj.attribute) --prints 6
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: C++ programmer going into LOVE
That could be rephrased as:T-Bone wrote:Code: Select all
example={} example.attribute = 4 function example:method() self.attribute = self.attribute + 1 end function newExampleObject() newObject = {} setmetatable(newObject,example) example.__index=example return newObject end
Code: Select all
example = {}
example.__index = example
...
function newExampleObject()
return setmetatable({}, example)
end
Re: C++ programmer going into LOVE
That's true. Your formulations are betterBlackBulletIV wrote:That could be rephrased as:T-Bone wrote:Code: Select all
example={} example.attribute = 4 function example:method() self.attribute = self.attribute + 1 end function newExampleObject() newObject = {} setmetatable(newObject,example) example.__index=example return newObject end
By the way, I've got a tutorial on metatables that might be useful.Code: Select all
example = {} example.__index = example ... function newExampleObject() return setmetatable({}, example) end
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Who is online
Users browsing this forum: Ahrefs [Bot] and 11 guests