Registering High Scores - Part 3

## Contents

###### Defining the Game Mechanics
1
Course Introduction
PREVIEW12m 47s
10
11
12

## The course is part of this learning path

Start course
Difficulty
Intermediate
Duration
2h 36m
Students
19
Ratings
5/5
Description

In this course, we begin building a game in Solidity, and more specifically, we begin to look at defining the mechanics and the components of the game.

Transcript

And now it gets a little bit complicated. If the highscoreMapping current position is not the address 0. And we set the highscoreMapping. So that's just another double check here. We are not talking about the same item that is in our, that we're just trying to put into the list then the... Our complete here is annoying. Then the highscoreMapping for; higherHighscoreAddress is the highscoreMapping. Current position; higherHighscoreAddress. And the reason for this is now we are going to put our current items place into the position that we are replacing from the item before. And obviously, that is pointing maybe if you're not having the first element but maybe the second or third element. Maybe that's pointing to another element on the left side on the higher side in our list. So, we have to put our item into that list and let it point to the higher item. Or else we have detached maybe the first or second item from our list. And if it's the highest item than the highscoreMapping for highscoreaddress is the address 0. So, if you have the top number one item in our highscore list, then we have no higher item, we have the highest item now, and then that's it.

So, the last thing that we have to do is really from the list perspective, is to reattach the item inside the current position. And that means if our highscoreMapping current position... and the highscoreMapping... And that is a lot of mappings now... So, we take the item, which is the next item, and then let it point to this item. And we have our current item, higherHighscoreAddress, and that must be the item that we just replaced. Now, here is little coding challenge, and that shouldn't hopefully be too much. First of all, we have here return. We don't continue here. Here's a little coding challenge. If we have the top  one position, then we have to assign a new highscoreHolder, or else this highscoreHolder here will afterwards point to the position number two in our list. So, if we just replace number one, then we also have to replace the highscoreHolder here. And that is something that you have to do here. It should be fairly easy, once you understood how these things work. In case you want to study how these things work and not just trust the code that I'm just writing, then there is a good idea just to replace this only game manager modifier and just play around with the HighscoreManager self-deployed. A HighscoreManager, add a couple of highscores for addresses, and let you give back the top 10 high scores, which we haven't done yet. We're going to do this in the next lecture. But in that case, you can always drill into the transaction with the debug button and check out what the values are of the different elements.