Tabula Rasa Collection help! I cannot accurately track the gems

Okay so I’m on Tablua Rasa on the first game development path here is my code so far

# Create your own game!
game.spawnMaze("forest", 4)

# Player Character
player = game.spawnPlayerXY("samurai", 10, 60)
player.maxHealth = 250
player.maxSpeed = 7
player.attackDamage = 10

# Goal to beat the game

# UI Tracking
ui.track(player, "health")
ui.track(game, "defeated")
ui.track(game, "collected")

# Gems
gem1 = game.spawnXY("gem", 30, 60)
gem1.value = 1
gem2 = game.spawnXY("gem", 44, 60)
gem2.value = 1
gem3 = game.spawnXY("gem", 60, 60)
gem3.value = 1
gem4 = game.spawnXY("gem", 12, 43)
gem4.value = 1
gem5 = game.spawnXY("gem", 12, 14)
gem5.value = 1
gem6 = game.spawnXY("gem", 28, 29)
gem6.value = 1
gem7 = game.spawnXY("gem", 45, 12)
gem7.value = 1

chest = game.spawnXY("chest", 60, 12)
chest.value = 150

# Munchkin Generators
mygen1 = game.spawnXY("generator", 27.5, 44)
mygen1.spawnType = "munchkin"
mygen1.spawnAI = "AttacksNearest"
mygen1.maxHealth = 65
mygen2 = game.spawnXY("generator", 28.5, 12)
mygen2.spawnType = "munchkin"
mygen2.spawnAI = "AttacksNearest"
mygen2.maxHealth = 65
mygen3 = game.spawnXY("generator", 52, 27)
mygen3.spawnType = "munchkin"
mygen3.spawnAI = "AttacksNearest"
mygen3.maxHealth = 65

# Extra forest blocks
game.spawnXY("forest", 52, 60)
game.spawnXY("forest", 20, 28)

I am having trouble with it tracking the gems collected and ive went back in to the previous levels and cant figure it out I’m stuck please help

Please send a screenshot and a description of the errors that you get when you run your code. Also a screenshot of your inventory would help given that

:fox_face: :fox_face::fox_face:

up in the upper right hand corner the

ui.track(game, “collected”)

is displayed and in theory it is suppose to track the gems as you collect them but it does’t, and the tracking of the enemy’s defeated is working just fine, there is no inventory system its in the first game development path the very last level. When I run the code I get zero errors and the game runs just fine its just when i pick up the gem it doesn’t track on the UI.

1 Like

Are you sure you have the exact and precise locations of the gems? Double check your code and make sure the locations are correct.

Also sometimes what happens in a level like this is your hero will bump into obstacles along the way. Sometimes you will have to put in coordinates away from the obstacle to ensure that the hero does not hit the obstacle. Try that also

1 Like

I will try and move the gems further away but I can pick them up just fine they just don’t get tracked on the UI

1 Like

It may be a glitch or bug problem. Contact @Chaboi_3000 or @Harry_the_Wanderer. Restarting your computer may help.

I think you need to use Game.on("collect",Actionname)

1 Like

I don’t understand how this is the solution, because this just throws an error. Actionname is not defined, but any other variable I put in there gives me a mismatch error. It expects a specific function. Is there an API somewhere that I missed?

1 Like

Hello and Welcome to CodeCombat Forums @Narishm! We hope you have a great experience on the forum. Before you go to far, we recommend that you read or community guidelines, which will give you a general understanding of the ins and outs of this forum.

Now regarding you issue,
Please further explain about it. Are you having the same problem as the creator of this topic? If so please post your code along with a screenshot. If you are having trouble with something else please start a new topic…


Yes, I was having the same issue as the creator of this forum. The Tabula Rasa mission in Game Development 1 doesn’t appear to be tracking things correctly. When you set a collection goal with game.addCollectGoal() the ui.track(game, "collected") does not track that goal.

ui.track(game, "collected")

Further when you add a defeat goal with game.addDefeatGoal(), and then you add a thrower, all of the spears/arrows count towards the defeated enemy goal.

I ended up just changing the win conditions and not tracking them because I could not find a way to make the UI tracking work.

1 Like

Could you please post your full not working code along with the link to the level. I wanna test your code to see what happens…

I had to go back and put the tracking code back in the level. Originally I had other things like locked chests and whatnot. I ended up removing those when I simplified the level. You can see the problem I am having with this code though. The level is the last one of Game Design 1, Tabula Rasa.

# Create your own game!
game.spawnMaze("forest", 21)
# Spawn a player with spawnPlayerXY(type, x, y)
player = game.spawnPlayerXY("captain", 12, 58)
# Player Attributes
player.maxHealth = 100
player.attackDamage = 15
player.maxSpeed = 20
# Add at least one goal!
game.addMoveGoalXY(60, 12)
game.addMoveGoalXY(44, 27)
game.addMoveGoalXY(12, 44)
#  Add Ui
ui.track(game, "time")
ui.track(game, "collected")
ui.track(game, "defeated")
ui.setText("directions", "Collect all the Gems.")
ui.setText("directions", "Defeat all the Ogres.")
ui.setText("directions", "Move to all the red Xs.")
ui.setText("directions", "The player must survive.")
# Spawn objects into the game with spawnXY(type, x, y)
# Items
game.spawnXY("gem", 60, 27)
game.spawnXY("gem", 28, 27)
game.spawnXY("gem", 60, 59)
game.spawnXY("gem", 28, 44)
game.spawnXY("gem", 28, 59)
game.spawnXY("gem", 12, 12)
game.spawnXY("gem", 44, 12)
# Enemies
game.spawnXY("munchkin", 12, 27)
game.spawnXY("munchkin", 28, 11)
game.spawnXY("munchkin", 44, 58)
game.spawnXY("munchkin", 44, 44)
game.spawnXY("thrower", 60, 43)

When I collect the Gems in the level the counter doesn’t increase. Also when the thrower on the right side throws the spears, they count as a defeated enemy when they hit something. But the counter seems to roll back if they vanish, unless you kill the thrower.

Also be careful when pasting the whole code in at once, I had a problem with it not displaying and flickering constantly.

Ok Slight complication, I forgot that I do not currently have the subscription so I cannot access the level :confused: . @Chaboi_3000 do you know what’s wrong with @Narishm’s code?

I got the subscription because I wanted to blast through all the levels. I figured it would be a good way to teach myself Python. I love the idea of this! I haven’t gotten super-deep into the code behind-the-scenes yet. I want to finish all the levels legit before I look at what makes them tick. :slight_smile:

As far as I understand there aren’t any errors in my code. There is a bit more trial and error here due to lack of an API document. There are a lot of things you can do in the code that aren’t listed in the interface. So if you don’t know they are there, you can’t use them properly. An example of this would be attributes, they aren’t showing up in the auto-complete for me; and there are definite ones that are used but aren’t listed. Like the .behavior attribute of enemies for example.

You’ll unlock them later in the game.

1 Like

I figured as much, and it’s interesting having to use simpler methods to do things when I know more advanced structures that will work better. I am trying not to skip ahead tho. :slight_smile:

There is still the issue of the UI Tracker not working properly though.

1 Like

I just paid for this program and I can’t believe I am running into the same problem as you did one year ago. No support have addressed this problem? I collect gems but the ui.track does not recognize it. I will write to support and post their message for other that comes after me.

@Stay_Safe As Chaboi mentioned above, you will learn/unlock the necessary code in later levels. However, give this a try…just add it to the end of your code:

game.collected = 0
player.on("collect", onCollect)
def onCollect(event):
    unit =
    item = event.other
    if item.type == "gem":
        game.collected += 1

OK, thank you. But since we have been collecting gems, spawning munichkins form a generator I thought that is what I could do. I will be a bit more humble and just move on. I will try to use the “behavior” on enemies to see if they attack me after spawned. Or is that code also coming later?

Thanks for answering.

1 Like

It is coming later, but should still be available to use now. The ‘unlocking’ part simply means that it is listed in the Events, or Methods sidebar. The same is true for most coding methods…you can use them if you know how, even if they haven’t been covered yet.