fork download
  1. local reputations = {
  2. {-1095 , "demon" },
  3. {-795 , "evil" },
  4. {-10 , "bad2" },
  5. {-5 , "bad1" },
  6. {0 , "normal" },
  7. {5 , "good1" },
  8. {10 , "good2" },
  9. {795 , "good3" },
  10. {1095 , "hero" }
  11. }
  12.  
  13. function getReputationName( points )
  14. local _, data = next( reputations )
  15. local result = data[2]
  16. for k, repdata in ipairs ( reputations ) do
  17. if repdata[1] <= points then
  18. result = repdata[2]
  19. else
  20. break
  21. end
  22. end
  23. return result
  24. end
  25.  
  26. print( getReputationName( -2000 ) )
  27. print( getReputationName( -10 ) )
  28. print( getReputationName( 0 ) )
  29. print( getReputationName( 5 ) )
  30. print( getReputationName( 2000 ) )
Success #stdin #stdout 0.02s 2540KB
stdin
Standard input is empty
stdout
demon
bad2
normal
good1
hero