Advertisement
LuaWeaver

Average - Lua

Apr 23rd, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.43 KB | None | 0 0
  1. --Using LOVE2D API
  2. function love.load()
  3.     input={}
  4.     curNum="wee"
  5. end
  6.  
  7. function love.keypressed(key)
  8.     if tonumber(key:sub(#key, #key)) then
  9.         if curNum=="wee" then curNum=="" end
  10.         curNum=curNum..tonumber(key:sub(#key, #key))
  11.     elseif key=="return" and not curNum=="wee" then
  12.         input[#input+1]=curNum
  13.         curNum="wee"
  14.     else
  15.         local num=0
  16.         for i, v in pairs(input) do
  17.             num=num+v
  18.         end
  19.         num=num/#input
  20.         print(num)
  21.     end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement