Because keys differ, GetInt does not find "Level" and returns default 1 instead of 5.
Final Answer:
Key names are case-sensitive, causing default value to be returned -> Option A
Quick Check:
Case-sensitive keys cause mismatch = C [OK]
Hint: Check key spelling and case carefully [OK]
Common Mistakes:
Ignoring case sensitivity of keys
Thinking PlayerPrefs.Save() is always required immediately
5. You want to save a player's high score and retrieve it later. Which sequence of code correctly saves the score 150 and then loads it with a default of 0 if not found?
hard
A. PlayerPrefs.SetString("highScore", "150");
int score = PlayerPrefs.GetInt("highScore", 0);
B. PlayerPrefs.SetInt("highScore", 150);
PlayerPrefs.Save();
int score = PlayerPrefs.GetInt("highScore", 0);
C. PlayerPrefs.SetInt(150, "highScore");
int score = PlayerPrefs.GetInt("highScore");
D. PlayerPrefs.SetInt("highScore", 150);
int score = PlayerPrefs.GetInt("highScore", 100);
PlayerPrefs.Save();
Solution
Step 1: Save the high score correctly
Use SetInt with key "highScore" and value 150, then call PlayerPrefs.Save() to ensure data is saved immediately.
Step 2: Retrieve the high score with default
Use GetInt with key "highScore" and default 0 to load the saved score or 0 if not found.
Final Answer:
PlayerPrefs.SetInt("highScore", 150);
PlayerPrefs.Save();
int score = PlayerPrefs.GetInt("highScore", 0); -> Option B
Quick Check:
SetInt + Save + GetInt with default = A [OK]
Hint: Save with SetInt + Save(), load with GetInt and default [OK]
Common Mistakes:
Mixing SetString with GetInt causing type mismatch
Not calling PlayerPrefs.Save() after setting data
Swapping key and value parameters
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.