Game "Achievements" not working

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Game "Achievements" not working

Post 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!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Game "Achievements" not working

Post 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.
User avatar
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

Re: Game "Achievements" not working

Post 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.
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Game "Achievements" not working

Post 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)
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Game "Achievements" not working

Post 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
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Game "Achievements" not working

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

Re: Game "Achievements" not working

Post 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.
Help us help you: attach a .love.
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Game "Achievements" not working

Post by TurtleP »

https://dl.dropbox.com/u/97639347/LOVE% ... /game.love

Just let me know when you've downloaded it.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Game "Achievements" not working

Post 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.
Last edited by Robin on Tue Dec 25, 2012 3:47 pm, edited 1 time in total.
Help us help you: attach a .love.
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Game "Achievements" not working

Post 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)
Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests