Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hello! Can you please explain this part  in a bit more detail. I am trying to make an achievement that is granted once player tries all 4 options of something.


# $ persistent.seen_endings.add("end1")

# $ ending_achievement.progress(len(persistent.seen_endings))

## This will prevent the achievement from being added to multiple times if the

## player sees the same ending multiple times.


I tried to do my own version and keep getting the error 

```

AttributeError: 'int' object has no attribute 'add'

or 

AttributeError: 'NoneType' object has no attribute 'add'


Do we need to define the class somewhere? I'm also severely sleep deprived so may be making simple mistake. Overall love this code a lot though!

You need to create a persistent set, e.g.

default persistent.seen_endings = set()

and then you will add to that set when you reach a relevant part in the game (that's this part:)

$ persistent.seen_endings.add("end1")

and in order to record that progress for an achievement, you can set the progress to the length of the list e.g.

$ ending_achievement.progress(len(persistent.seen_endings))

Sets are used because they can't have duplicates, so the length of the list will be the number of unique endings the player has seen, and it won't matter if they go through the same ending multiple times/it won't count them more than once towards the achievement.

Thank you for the speedy response! I really appreciate the breakdown.

I discovered that the issue was actually with the name I was giving my variable...I'm still not sure why it was happening but I suspect it was too similar to the name of something else in my project. Once I followed your code with a different name it worked!

Thanks again for your contributions as I'm really excited to have this feature and I will be crediting you in the final release!

I know this is sort of old but i'm having trouble understanding the last part

$ ending_achievement.progress(len(persistent.seen_endings))

so what exactly am i supposed to put in the parentheses? just the persistent.myachievement_name? or am i supposed to put in the "end1, end2..." in it?

persistent.seen_endings is a variable you make yourself, to track the unique endings the player has gone through (as described in the earlier message). You invent the name for that. I called the example persistent.seen_endings, assuming it was a collection of the endings the player has seen. You could call it persistent.secrets_learned or persistent.jokes_heard or persistent.clovers_found, whatever makes sense. It needs to be persistent to be tracked across all playthroughs.

I suggest you read up more on Python sets to understand what this variable does - it's really only a slightly simplified way of tracking unique occurrences of something such as tallying the number of unique endings the player has seen. If you find this confusing, it's perfectly fine to do a longer method, such as by having

default persistent.bad_end = False
default persistent.normal_end = False
default persistent.good_end = False

and then tallying them up yourself for the achievement check e.g.

label good_ending:
  $ persistent.good_end = True
  if persistent.good_end and persistent.bad_end and persistent.normal_end:
    # Saw all 3 ends
    $ ending_achievement.progress(3)
  elif persistent.bad_end or persistent.normal_end:
    # Saw the good end and either the bad or normal end
    $ ending_achievement.progress(2)
  else:
    # Only saw the good end (this one)
    $ ending_achievement.progress(1)

Longer code you understand is basically always better than shorter code you don't!

Thank you! I'll do some learning cause I do want to shorten code where I can. my game's long enough as it is T^T