Objective?

Hi,

How can I have objective/achievement system for my game? I have a simple fruit-ninja like game that the achievements will be, at least for start, simple things like in case of fruit ninja cut 5 bananas to more complex ones like do some stuff in a chain like cut a banana then a watermelon then a cucumber.

My guts tells me that I somehow should make a data structure for them and fill them based on game design. Then feed all these into a big table and have indexes on active ones. I’m not sure if it’s the case though.

And then after each event in the game, i.e. something interesting happens, I check it with the current objective and if it’s true, clear it out. This is the part that I’m most clouded: How to check for different criteria based on different objectives? For example, one time it should count cut lemons then it should watch a sequence of actions then it should watch for another event(s).

Thanks.

  1. You want to record player actions to a table. What you record really just depends on you, but the simplest form is that say, every time you cut a banana, then you increment the table.bananaKills. So your gut is right; you need structure (tables)

  2. For more complicated features, like “cut 5 bananas in a row”, what you should do is also make a table for “recent” data and then run a compare function on it. So you’d be incrementing bananaKills but also adding something to the end of a table.recentActions.

  3. Checking is simply setting rules, ie: you might want a multi-stage table:

[lua]local levels = {} – a list of all of your levels

levels[1] = {

  name = “Hungry Bananas”,

  world = 1, – this is “1-1”

  stage = 1, –  you’re on the first stage of this level

  objectives = {

    { type=“slice”, count=5, food=“banana” }, – the first objective is to slice 5 bananas

    { type=“eat”, count=2, food=“apricot” } – the second objective is to eat 2 apricots

}[/lua]

“stage” is simply a counter. When you complete the first objective, increment stage, and now the objective is the second one, not the first. The table also gives you the data needed to check if the objective is accomplished.

Thanks Richard9,

What way do you recommend of communicating between the objective system and the game?

It’s a difficult question to answer because it really depends on the architecture of your game.

The ideal Corona way is to use “custom event calls”. So just as you have touch events, you could have “objective” events, and every time you want to check/update/etc an objective, you send one of those events.

The difficult part with custom event calls is that they aren’t global like “Runtime” and “touch”. You have to point them at your object, which is probably the objective table.  It takes a bit of work to get this functional but it makes sense with time. You literally make an event table, so just like touch has .x and .y, you define the stuff you want to send.

Custom Events in Corona

  1. You want to record player actions to a table. What you record really just depends on you, but the simplest form is that say, every time you cut a banana, then you increment the table.bananaKills. So your gut is right; you need structure (tables)

  2. For more complicated features, like “cut 5 bananas in a row”, what you should do is also make a table for “recent” data and then run a compare function on it. So you’d be incrementing bananaKills but also adding something to the end of a table.recentActions.

  3. Checking is simply setting rules, ie: you might want a multi-stage table:

[lua]local levels = {} – a list of all of your levels

levels[1] = {

  name = “Hungry Bananas”,

  world = 1, – this is “1-1”

  stage = 1, –  you’re on the first stage of this level

  objectives = {

    { type=“slice”, count=5, food=“banana” }, – the first objective is to slice 5 bananas

    { type=“eat”, count=2, food=“apricot” } – the second objective is to eat 2 apricots

}[/lua]

“stage” is simply a counter. When you complete the first objective, increment stage, and now the objective is the second one, not the first. The table also gives you the data needed to check if the objective is accomplished.

Thanks Richard9,

What way do you recommend of communicating between the objective system and the game?

It’s a difficult question to answer because it really depends on the architecture of your game.

The ideal Corona way is to use “custom event calls”. So just as you have touch events, you could have “objective” events, and every time you want to check/update/etc an objective, you send one of those events.

The difficult part with custom event calls is that they aren’t global like “Runtime” and “touch”. You have to point them at your object, which is probably the objective table.  It takes a bit of work to get this functional but it makes sense with time. You literally make an event table, so just like touch has .x and .y, you define the stuff you want to send.

Custom Events in Corona