So at this point, you should feel familiar with maps. So familiar, it’s time for a challenge. In your challenge, I want you to create an RPG character and store the character in a map. Give him the name ‘Ratatast the Smelly’. Give him a strength, intelligence and dexterity. Set his strength to weak, his intelligence to brilliant, and his dexterity to clumsy. Once done, print out his stat values to the screen. Pause the video now and give it a shot.
How’d that challenge go for you? Were you able to create Ratatast the Smelly? Let’s do this now. Head over to dartpad.dev and add the following:
var character = { 'name': 'Ratatast the Smelly', 'strength': 'weak', 'intelligence': 'brilliant', 'dexterity': 'clumsy' };
This is kind of hard to read. Lets add some line breaks to make this legible.
var character = {
'name': 'Ratatast the Smelly',
'strength': 'weak',
'intelligence': 'brilliant',
'dexterity': 'clumsy'
};
Dart doesn’t care about spacing, so we can use it layout our code in a way that’s easy to understand. Now let’s print out his attributes.
print(character['name']);
print(character['strength']);
print(character['intelligence']);
print(character['intelligence']);
Run the program. And look at that, we have our character on the screen. Nice work!