Page 2 of 2
Re: The Five Second Game
Posted: Mon Jan 02, 2012 3:53 am
by Ryne
MarekkPie wrote:That's awesome, Ryne. Thanks a bunch.
no problem, I didn't really stick to your games resolution or anything so if you want I can resize whatever you need.
the graphics are also meant to scale, so they are pretty tiny and should be scaled using "love.graphics.scale(4, 4)"
you can use this piece of code to make sure they scale properly as well.
Code: Select all
local oldNewImage = love.graphics.newImage
function love.graphics.newImage(...) -- basic code to filter image scaling to nearest
local img = oldNewImage(...)
img:setFilter("nearest", "nearest")
return img
end
Re: The Five Second Game
Posted: Mon Jan 02, 2012 3:14 pm
by Robin
MarekkPie wrote:I know Lua doesn't natively support namespaces in the traditional sense, so my understanding is that people simply wrap a table around their code and call it a namespace. My only issue is that I'm not sure it will work with my current set up. Here is my dilemma:
It doesn't work, because it's not a namespace at all, in Lua
{} is just the notation for table literals.
Inside a table literal, the only thing you can have is
[key] = value, where key and value are both expressions.
Example:
Code: Select all
a = {5, 6, 7} -- short for a = {[1] = 5, [2] = 6, [3] = 7}
b = {q = 10} -- short for b = {['q'] = 10}
c = {f = function () end} -- short for c = {['f'] = function () end}
The way namespaces are usually used in Lua is the following way:
Code: Select all
namespace = {}
function namespace.a ()
end
function namespace.b ()
end
Re: Gluttony (formerly The Five Second Game)
Posted: Mon Jan 02, 2012 7:09 pm
by MarekkPie
Uploaded new version in the original post!
Thanks Robin.
I found online a nice way to do namespaces without having to constantly retype namespace. It'll also allow for some private functions within the namespace/package.
Code: Select all
-- In file "namespace.lua"
do -- <== Important if you want to be able to give the namespace a new alias
local varA
local varB
local function funcA()
print("hidden")
end
local function funcB()
funcA()
end
namespace = {
varB = varB,
funcB = funcB,
}
return namespace -- <== Allows for new alias
end -- <== Allows for new alias
Anything you want to be private, simply don't give it an alias within your namespace. When you need access to the namespace, in another file, do this:
Code: Select all
local N = require "--[[PATHTO: namespace.lua]]"
B = N.varB
A = N.varA -- nil (since there is not an alias for varA)
N.funcA() -- error (since there is not an alias for funcA)
N.funcB() -- prints "hidden"
Re: Gluttony (formerly The Five Second Game)
Posted: Tue Jan 03, 2012 9:49 am
by kikito
There is an implicit "do ... end" on each file (they have their own scope already built in). You don't need to add do .. end when you create a new file. Just make whatever you don't want to share local, and don't attach it to the returned table.
Re: Gluttony (formerly The Five Second Game)
Posted: Tue Jan 03, 2012 10:47 am
by Robin
Also, N.varB is nil as well, since there is no varB = 6 or something in namespace.lua.
Re: Gluttony (formerly The Five Second Game)
Posted: Tue Jan 03, 2012 4:42 pm
by MarekkPie
Robin wrote:Also, N.varB is nil as well, since there is no varB = 6 or something in namespace.lua.
My bad. Meant to put in an assignment for those but forgot.
kikito wrote:There is an implicit "do ... end" on each file (they have their own scope already built in). You don't need to add do .. end when you create a new file. Just make whatever you don't want to share local, and don't attach it to the returned table.
Hrmm, I was getting a lot of weird errors whenever I didn't put the do...end block around my file. It was on several files, so it wasn't a localized problem. But I just tested it and it worked out...hrmm...(/goinginsane)
Re: Gluttony (formerly The Five Second Game)
Posted: Wed Jan 04, 2012 8:02 am
by spirulence
This is a fun little game! I don't have a mouse handy, so my scores sat in the low 200s. Yikes!
I could almost hear the cheesy frantic chiptune that would go along with this.
Re: Gluttony (formerly The Five Second Game)
Posted: Wed Jan 04, 2012 8:06 am
by MarekkPie
Thanks a lot, spirulence.
Even with a mouse, the best I've gotten is 290. There definitely is an upper limit, just based on the available space, and for me, a good game is 260-290.
Have you figured out how to cheat yet? I didn't put it in intentionally, but I decided to leave it in even after I figured it out.