Multiple questions : math.random, objects, events ...
Posted: Mon Apr 14, 2014 12:02 pm
Hello everybody !
I'm barely new with Love AND Lua, i hope i won't ask stupid questions !
First of all, i'm training on this framework with a small game. Basicaly, a little window appears on top of the screen with a text inside. It moves down and the user loses if he doesn't kill the text before it reaches him. To kill the text, you just have to type what the text says.
SO
I'm using love.math.random to generate a number (between 1 and the total lenght of my dictionnary) to pop a word on the screen. BUT whenever i compile my soft, the number i get is always the same ! I'm using the math.random in an independant function :
Am i doing something wrong ?
Second, is there a way to declare objects (i have a Java way of thinking about objects). So i could easely create a text-object with attributes and methods and everything .... I've already read the chapter 16 of LUA programming, but i don't get the method to actually construc an object ...
And for my last request, how do events are managed ?
For the moment, i'm using a frame counter in my love.update(dt)
And then in my love.draw() :
I saw the love.event wiki, but the exemple show keyboard inputs, so i guessed i won't be able do manage the creation of my 'words' with that.. or can i ?
Thanks for the replies !
luv
I'm barely new with Love AND Lua, i hope i won't ask stupid questions !
First of all, i'm training on this framework with a small game. Basicaly, a little window appears on top of the screen with a text inside. It moves down and the user loses if he doesn't kill the text before it reaches him. To kill the text, you just have to type what the text says.
SO
I'm using love.math.random to generate a number (between 1 and the total lenght of my dictionnary) to pop a word on the screen. BUT whenever i compile my soft, the number i get is always the same ! I'm using the math.random in an independant function :
Code: Select all
function dico ()
liste={"test", "test1", "test2", "test3", "test4", "test5", "test6"}
Count = 0
for _ in pairs(liste) do
Count = Count + 1
end
n1=love.math.random(1, Count)
return liste[n1]
end
Second, is there a way to declare objects (i have a Java way of thinking about objects). So i could easely create a text-object with attributes and methods and everything .... I've already read the chapter 16 of LUA programming, but i don't get the method to actually construc an object ...
And for my last request, how do events are managed ?
For the moment, i'm using a frame counter in my love.update(dt)
Code: Select all
timer=0
function love.update(dt)
timer = timer+dt
timer = math.ceil(timer)
print(timer)
end
Code: Select all
if timer > 20 then
love.graphics.print(mot2, positionx, positiony))
positiony=positiony+1
end
Thanks for the replies !
luv