[Adventurer] Persistence Pays

The level Persistence Pays is ready for playtesting.

This level takes place in the Game Dev 1 campaign, it introduces the db.add(key, value) command which allows students to persist information between plays of their game.

Interesting. Does this count anyone playing this page, or only mine?

Is it possible to track two things with the same name?


ui.track(game, 'defeated')
ui.track(db, 'defeated')

Also, what about tracing best scores?

ui.track(db, "best")

def onVictory(event):
    
    if game.defeated > db.best:
        db.add('best',game.defeated-db.best)

In this level it’s effectively just for you, but if you use these db commands in a level like Tabula Rasa, and then share the link to your game, it’ll be for everyone who plays your game.

Good idea :slight_smile: This is just the beginning. The students in Game Dev 1 don’t know how to do a lot yet, but for the more advanced folks, have fun with it!. Josh made a demo game that counted how the different ways the players were killed :wink:

We will teach more advanced uses in later Game Dev campaigns, and evolve the complexity of what the db commands can do, until it’s more like using a real database in the later courses.

2 Likes

Hi,

In this level, you need to track the game’s defeated property, but it’s not tracking mine.

I think that this bit of code:

Show the value of the “defeated” property of the game object

ui.track(db,“defeated”)

Which is already there i.e. I didn’t add it. Does this, obviously it doesn’t otherwise I’d be finishing the level.

What am I missing?

Track the game`s “defeated” property , not the “defeated” property of db object.

1 Like

How do I do this part?
21%20PM

Have you figured this out yet? I’ve tried every combination with db.set and db.add, and I still can’t get it to accept. I’m clearly doing something wrong.

Can you post the code here so we can assist you?

This is bugged you set a loop to where you cannot put right code without error and no code without not finishing

Help. Which command refers to the game’s defeated property?

You can use a database to store persistent data.

Persistent data stays the same between plays of your game!

generator = game.spawnXY(“generator”, 60, 40)
generator.spawnType = “munchkin”
generator.spawnDelay = 1
player = game.spawnPlayerXY(“raider”, 36, 30)
player.maxHealth = 70000
player.attackDamage = 1000
game.addSurviveGoal(8)

db stands for database

db.add(key, value) increments a value stored in the database.

This adds 1 to the “plays” key in the database.

db.add(“plays”, 1)

Show the value of the “plays” and other keys in the db

ui.track(db, “plays”)
ui.track(db, “wins”)
ui.track(db, “total defeated”)

ui.track(game, “time”)

Show the value of the “defeated” property of the game object

ui.track(db, “defeated”)

The code below will run when the player wins the game.

def onVictory(event):
db.add(“wins”, 1)
db.add(“defeated”, 0)
# Use db.add(key, value) to add the value of
# game.defeated to the database with the key “total defeated”
db.add(“total defeated”, game.defeated)

db.set("defeated", game.defeated)

game.on(“victory”, onVictory)

Welcome‌ ‌welcome‌ ‌to‌ ‌the‌ ‌forum!‌ ‌It‌ ‌is‌ ‌a‌ ‌lovely‌ ‌place‌ ‌where‌ ‌you‌ ‌can‌ ‌share‌ ‌all‌ ‌kinds‌ ‌of‌ stuff‌ ‌(appropriate‌ ‌of‌ ‌course),‌ ‌share‌ ‌bugs,‌ ‌and‌ ‌even‌ ‌get‌ ‌assistance‌ ‌for‌ ‌code!‌ ‌We‌ ‌suggest‌ ‌that‌ ‌you‌ ‌review‌ ‌this‌‌ topic‌ ‌which‌ ‌shows‌ ‌all‌ ‌essentials‌ ‌of‌ ‌this‌ ‌board!‌ ‌And‌ ‌we‌ ‌suggest‌ ‌you‌ ‌review‌ this topic‌ ‌which‌ ‌shows‌ ‌how‌ ‌to‌ ‌post‌ ‌your‌ ‌code‌ ‌correctly!‌ ‌Thanks!!‌ ‌ :partying_face: :partying_face:
Please format your code correctly!
Lydia

when I did ui.track(db, “defeated”) it is showing that that cant work so what do i do now

hey there, welcome to the forum please review these rules
and also the person you are replying to probably won’t see it.

1 Like

how would you track it in db tho.

Pls don’t necro post talking to people who have not been online for years

my bad liouafg iowlU IOSHYIWSEJH LIUE45

hola shelly yo no se ingles y tambien no se quien tu eres.