Hey guys, I'm wondering how I would go about converting this BASIC code to LUA.. What's getting me is the "field X[4] and "en:enemy = new enemy". I've been looking at code from the people on this forum, but couldn't find anything like this; I really should read Programming in Lua. But, if anyone could be bothered to have a go, please do
type enemy
field X[4]
field Y[4]
end type
function createEnemy:enemy( ..parameters.. )
local en:enemy = new enemy
en.x[0] = 10
en.x[1] = 20
en.y[0] = 10
en.y[1] = 20
return en
end function
function drawEnemy(en.enemy, size, color)
...
end function
NÖÖB wrote:Hey guys, I'm wondering how I would go about converting this BASIC code to LUA.. What's getting me is the "field X[4] and "en:enemy = new enemy". I've been looking at code from the people on this forum, but couldn't find anything like this; I really should read Programming in Lua. But, if anyone could be bothered to have a go, please do
type enemy
field X[4]
field Y[4]
end type
function createEnemy:enemy( ..parameters.. )
local en:enemy = new enemy
en.x[0] = 10
en.x[1] = 20
en.y[0] = 10
en.y[1] = 20
return en
end function
function drawEnemy(en.enemy, size, color)
...
end function
Where did you get the code from ? that does not look like basic to me it looks like mixed up lua
Just from what I can see its missing some code from somewhere like I see it is stating tables but no table as been defined anywhere the en:enemy is enemy, as it is = to new enemy
from what I can see enemy should be soemthing like
I don't know hardly anything about Basic, but it seems that Basic has a class (type) system. This isn't the case in Lua, you have to use the language's data structure "tables" to do it, along with metatables. However, there are a number of libraries that take care of this for you, like MiddleClass.
"Type enemy" is like a blueprint for an enemy-being, it would include parameters like X, Y, size, strenght, image, inventory..
"Function CreateEnemy:Enemy(100, 100, small, mediumstrong, lizard) creates an instance of a new enemy.. it could be used over and over again, spawning enemies of different appearance, strength etc.
I just used x[4] as an example to show that it's possible
NÖÖB wrote:"Type enemy" is like a blueprint for an enemy-being, it would include parameters like X, Y, size, strenght, image, inventory..
"Function CreateEnemy:Enemy(100, 100, small, mediumstrong, lizard) creates an instance of a new enemy.. it could be used over and over again, spawning enemies of different appearance, strength etc.
I just used x[4] as an example to show that it's possible
you would have to build the whole function far as I know as love is a game framework not really a rebuild default engine and i think thats that Basic is
so you would need to set the love.newgraphics command i think that will set the x and y and you would need to tell it the image file and so on, sorry I
have not got really deep with love I will start in the next few months soon as I get my IDE stable
Sir Kittenface Möko IDE Codename (Erös) Returns Soon
I am dyslexic so if any of my replys confusing please just ask me to reword it as this will make things a lot easier for all parties lol.
NÖÖB wrote:Hey guys, I'm wondering how I would go about converting this BASIC code to LUA.. What's getting me is the "field X[4] and "en:enemy = new enemy". I've been looking at code from the people on this forum, but couldn't find anything like this; I really should read Programming in Lua. But, if anyone could be bothered to have a go, please do
type enemy
field X[4]
field Y[4]
end type
function createEnemy:enemy( ..parameters.. )
local en:enemy = new enemy
en.x[0] = 10
en.x[1] = 20
en.y[0] = 10
en.y[1] = 20
return en
end function
function drawEnemy(en.enemy, size, color)
...
end function
Forget about translating Basic code directly to lua. Your code will look better in Lua! Read about MiddleClass here: http://love2d.org/wiki/MiddleClass and do something like:
require 'middleclass'
Enemy=class('Enemy')
function Enemy:initialize(x1,x2,y1,y2)
self.X={x1,x2}
self.Y={y1,y2}
end
function createEnemy(x1,x2,y1,y2)
return Enemy:new(x1,x2,y1,y2)
end
local e1=createEnemy(10,20,10,20)
print(e1,e1.X[1], e1.Y[1])
Notes:
- you dont need/can not create "types" (records?) in Lua
- tables are 1-based