Page 2 of 2

Re: stupid game

Posted: Mon Oct 28, 2013 1:13 pm
by zenith
totally confused with timers
sample program shoud count every second 5 times

Code: Select all

function love.load()
	display = {}
	timer = 0
end

function love.draw()
	love.graphics.print(timer, 10, 10) -- showing current timer
	for i,v in ipairs(display) do
		love.graphics.print(v, 10, 10 + i*15)
	end
end

function love.update(dt)
	timer = timer + 1*dt -- go!

	for i=1,5 do
		if timer >= i then
			table.insert(display, i.." second")
		end
	end
end
of course it don't work
is there any tutorials about timers and events?

Re: stupid game

Posted: Mon Oct 28, 2013 2:29 pm
by Robin

Code: Select all

function love.load()
	display = {}
	timer = 0
        times_left = 5
end

function love.draw()
	love.graphics.print(timer, 10, 10) -- showing current timer
	for i,v in ipairs(display) do
		love.graphics.print(v, 10, 10 + i*15)
	end
end

function love.update(dt)
        if times_left > 0 then
		timer = timer + dt
		if timer >= 1 then
			times_left = times_left - 1
			timer = 0
			table.insert(display, i.." second")
		end
	end
end
Understand how it works?

EDIT: weird indentation, please ignore it.

Re: stupid game

Posted: Sun Nov 10, 2013 7:36 am
by zenith
thanks!

timers are weird indeed. if i have e.g. 5 simultaneous events on screen than i must have 5 different timer vars on love.load? that's not looks very handy for me.
delta time is a love's thing or lua's?

Re: stupid game

Posted: Thu Nov 14, 2013 10:13 am
by zenith
here's the situation: i have tables inside the table and i need to draw them. my variant don't work, of course

Code: Select all

function menuBattleSpawn()
	menuBattle = {
		attack = {
			name = 'Attack',
			entry = {}
		}, item = {
			name = 'Items',
			entry = {}
		}, skill = {
			name = 'Skill',
			entry = {}
		}
	}
end

function menuBattleDraw()
	love.graphics.setFont(big)
	for i,v in ipairs(menuBattle) do
		for ind,val in ipairs(v) do
			love.graphics.print(ind.name, 100, i+200)
		end
	end
end

Re: stupid game

Posted: Thu Nov 14, 2013 10:25 am
by micha
The table that you create is not an array-type table. The entries are

Code: Select all

menuBattle.attack
menuBattle.item
menuBattle.skill
The iterator "ipairs" only iterates over table entries with numeric keys. For example (these do not exist in your code):

Code: Select all

menuBattle[1]
menuBattle[2]
You can iterate of all entries (not only the ones with numeric keys) by using "pairs" instead of "ipairs". In that case you have to keep track of the coordinates by hand.

Code: Select all

local y = 100
for i,v in pairs(menuBattle) do
  love.graphics.print(v.name, 100, y)
  y = y + 50
end

Re: stupid game

Posted: Tue Jan 07, 2014 10:23 am
by zenith
hey guys! 0.9.0 is out, huh
anyway, can anyone please suggest any tutorial on love.filesystem?

Re: stupid game

Posted: Tue Jan 07, 2014 7:59 pm
by davisdude
Which ones in particular? I can explain some of the ones I use more, though:

love.filesystem.load-
Loads a file, but does not run it.
Very basic example:

entity.lua:

Code: Select all

local ent = {
     registered = {
          apple = love.fileysytem.load( "entities/apple.lua" ) -- Assuming there is a file called "apple.lua" inside a folder called "entities" inside your main directory.
          banana = love.filesystem.load( "entities/banana.lua" ) --Remember, this just loads it.
     }
} --I do the table this way because it saves a bit of memory. 

function ent.new( name )
     if not ent.registered[name] then error( "Entity error: did not register "..name.."." ) end
     local e = ent.registered[name]()
     return e
end

return ent
main.lua:

Code: Select all

local ent = require( "entity.lua" )

function love.load()
     apple = ent.new( "apple" )
end
That's really the one I use the most. If you want a particular example, just ask! :)