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!
Game "Achievements" not working
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Game "Achievements" not working
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.
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
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:
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
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.
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 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
Well, that didn't work either, even if the table is in love.update(dt)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.
Re: Game "Achievements" not working
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.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
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
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.
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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Game "Achievements" not working
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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Game "Achievements" not working
I get an error: (when clicking "play")
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.
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'
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.
Re: Game "Achievements" not working
Oh, my bad on that.Robin wrote:I get an error: (when clicking "play")Don't you get the same error?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'
I'm looking into it.
game.lua 38:
replace achievement:update(dt)
with
ach:update(dt)
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 2 guests