In his game, he is a loner because he is the bad guy. He doesn’t like being lonely and feeling like a loser, so he leaves his game to join another game where he can be a hero and earn a medal to be at the top of the tower. Gene, the hero of Ralph’s game, doesn’t want him to have a medal or be at the top. He crashes his jet into the game called Sugar Rush.
When he wakes up, his medal is at the top of a peppermint tree. As he climbs it, Vanellope, a character and princess of Sugar Rush, takes his medal and uses it to enter a race. She promises to give him back his medal after she wins the race. After that, King Candy retrieves the medal and tells Ralph that Vanellope can’t race because her glitch will cause the game to be unplugged, which would kill her since she can’t leave the game and hasn’t won the race. To protect her, Ralph destroys the car they built together.
He hears from King Candy’s minion that King Candy didn’t want her racing so she wouldn’t expose him as the imposter. Ralph and Vanellope then work together to expose King Candy, and she wins the race, causing him to reveal his true self. Vanellope ultimately wins the race, and her code is restored, making her the princess of Sugar Rush.
