Page 1 of 2

Game "Achievements" not working

Posted: Sun Dec 23, 2012 4:27 am
by TurtleP
Hello,

My game is going to have unlockable achievements, and my friend set up some code that should handle it.

https://dl.dropbox.com/u/97639347/Proje ... /store.lua

However, it's not firing the unlock function for some reason. Any help would be appreciated!

Re: Game "Achievements" not working

Posted: Sun Dec 23, 2012 10:58 am
by bartbes
Regardless of the fact that the conditions never change, all your tests are only executed once, namely when the ach table is created.
Instead of "deaths == 10", you probably want "function() return deaths == 10 end" and then execute that to test, because currently all contain a constant false.

Re: Game "Achievements" not working

Posted: Sun Dec 23, 2012 2:50 pm
by Ubermann
Also why you have two tables, one for the achievements and other for the true/false?

You can simple have one single table with all that info but in a more ordered way, for example:

Code: Select all

achievements = { {name = "Godlike",
                 description = "Kill 10000 enemies",
                 completed = false} ,
                 {name = "Fool",
                  description = "Die 999 times",
                  completed = false} }
And access each sub-table like this: achievements[1].name. This will return "Godlike"; achievements[2].description will return "Die 9999 times"

And access every element with

Code: Select all

for i, v in ipairs(achievements) do
    print(v.name .. " " .. v.description .. " " .. tostring(v.completed))
end

I recommend an indexed table because if you add later on more elements to each table pair, you will need to change a lot of things in your code if you don't use indexes. But with indexes, table[1].name will always be the same, without matter if .name is in the first position of the table or in the last.

Re: Game "Achievements" not working

Posted: Sun Dec 23, 2012 2:57 pm
by TurtleP
bartbes wrote:Regardless of the fact that the conditions never change, all your tests are only executed once, namely when the ach table is created.
Instead of "deaths == 10", you probably want "function() return deaths == 10 end" and then execute that to test, because currently all contain a constant false.
Well, that didn't work either, even if the table is in love.update(dt)

Re: Game "Achievements" not working

Posted: Sun Dec 23, 2012 4:50 pm
by coffee
Ubermann wrote:Also why you have two tables, one for the achievements and other for the true/false?

You can simple have one single table with all that info but in a more ordered way, for example
Even that I understand your thought IMHO I think it's wise for performance questions to divide between two tables of not accomplished achievements and obtained achievements.

That way you won't need to waste parsing also the obtained achievements. That because In your one-table method you will always need to see if the achievement is done (completed) to check if needs to be verified or not. Seems like slowing down the achievement checking.

Also TurtleP you can check this viewtopic.php?f=5&t=9286

Re: Game "Achievements" not working

Posted: Tue Dec 25, 2012 4:29 am
by TurtleP
Well, my friend figured out how to make them work, so it's all good! (The guy who made the achivements originally for my game, not the one coffee provided)

There's a problem though..

https://dl.dropbox.com/u/97639347/LOVE% ... s/code.txt

Each time it's drawing the achievement, I want it to fade out on a timer. However, timer or subtracting self.transparent only is done one time. It's weird. So instead of going 2-dt-dt-dt.. it does 2-dt STOP.

Re: Game "Achievements" not working

Posted: Tue Dec 25, 2012 3:21 pm
by Robin
Could you upload your .love for us? I think I have an idea what the issue is, but I don't know for certain and can't exactly help you unless I have the full source.

Re: Game "Achievements" not working

Posted: Tue Dec 25, 2012 3:32 pm
by TurtleP
https://dl.dropbox.com/u/97639347/LOVE% ... /game.love

Just let me know when you've downloaded it.

Re: Game "Achievements" not working

Posted: Tue Dec 25, 2012 3:39 pm
by Robin
I get an error: (when clicking "play")

Code: Select all

Error: Classes/achievement.lua:21: attempt to perform arithmetic on field 'transparent' (a nil value)
stack traceback:
	Classes/achievement.lua:21: in function 'update'
	States/game.lua:38: in function 'conditions'
	States/game.lua:59: in function 'game_update'
	main.lua:325: in function 'update'
	[string "boot.lua"]:407: in function <[string "boot.lua"]:373>
	[C]: in function 'xpcall'
Don't you get the same error?

I'm looking into it.

EDIT:

I found the solution. You are calling achievementlist() in love.update. Call it in love.load. Why? Because now, you keep recreating the achievementlist over and over again, so of course self.transparent doesn't go down. It keeps getting reset. (Also, follow bartbes' advice and put the conditions into a function, that you call when you check for the condition.

Re: Game "Achievements" not working

Posted: Tue Dec 25, 2012 3:42 pm
by TurtleP
Robin wrote:I get an error: (when clicking "play")

Code: Select all

Error: Classes/achievement.lua:21: attempt to perform arithmetic on field 'transparent' (a nil value)
stack traceback:
	Classes/achievement.lua:21: in function 'update'
	States/game.lua:38: in function 'conditions'
	States/game.lua:59: in function 'game_update'
	main.lua:325: in function 'update'
	[string "boot.lua"]:407: in function <[string "boot.lua"]:373>
	[C]: in function 'xpcall'
Don't you get the same error?

I'm looking into it.
Oh, my bad on that.

game.lua 38:

replace achievement:update(dt)

with

ach:update(dt)