I have a game in RoR. The game breaks down like this. There are Levels, Levels have Missions and Missions have Gameplays (your attempt to complete the mission).
To pass a level you just need to complete 1 mission. So in my Level model, I am trying to write method to determine if a user has passed the level and can’t seem to get it. I need to return true if the gamplay score is > the score required to pass the mission.
This is where I’m at. How can I exit the loop and return true if I find a Gameplay with a score > the mission score?
def user_has_passed(user)
self.missions.each do |mi|
plays = Gameplay.where(:user_id => user.id, :mission_id => mi.id)
#code here, if a play.score > mi.score return true, else return false
end
end
Why don’t you add one more part to the where call?
And with this if you get any plays (good.plays.size > 0) you are good
Or with your query, you need one more loop