stupid game

Show off your games, demos and other (playable) creations.
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: stupid game

Post 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?
ping pong
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: stupid game

Post 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.
Help us help you: attach a .love.
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: stupid game

Post 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?
ping pong
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: stupid game

Post 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
ping pong
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: stupid game

Post 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
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: stupid game

Post by zenith »

hey guys! 0.9.0 is out, huh
anyway, can anyone please suggest any tutorial on love.filesystem?
ping pong
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: stupid game

Post 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! :)
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest