Discord
Login
Community
DARK THEME

how do I abbreviate numbers in my incremental

so everything else works the buttons and the point system the problem is that the numbers start to become unreadable at bigger amounts until we get this 10000000000000000 I need it to instead show abbreviations like that number I showed you to be like 10.000 qd and other numbers like 1000 as 1.000k 1285039 as 1.285m can I please get help with this I been stuck on it for a week

do something like

init = function()
  mode = "normal"
  realNUM = 0
  number = realNUM
end

update = function()
  realNUM += 10
  if mode == "normal" then number = realNUM end
  if realNUM > 999 then mode = "thousands" end
  if mode == "thousands" then 
    number = floor(realNUM / 1000) + "K" 
  end
end

draw = function()
  print(number)
end

hope this helps! :D


or you can create a function that calculates your number for you; here is an example

// Function to shorten large numbers
abbreviate = function(number)
  if number < 1000 then return floor(number) end
  
  // Standard English abbreviations: k, Million, Billion, Trillion...
  local units = ["k", "M", "B", "T", "Qd", "Qi", "Sx", "Sp"]
  local index = -1
  local value = number

  while value >= 1000 and index < units.length - 1
    value /= 1000
    index += 1
  end

  // Example: 1.285M
  return (floor(value * 1000) / 1000) + units[index]
end

init = function()
  // EXAMPLES (test these values)
  score1 = 1285039                // Should show: 1.285M
  score2 = 100000000000000000     // Should show: 100Qd
  score3 = 1500                   // Should show: 1.5k
end

update = function()
  // Your game logic here
end

draw = function()
  screen.clear("black")
  
  // Displaying the examples on screen
  screen.drawText(abbreviate(score1), 0, 40, 20, "white")
  screen.drawText(abbreviate(score2), 0, 0, 20, "cyan")
  screen.drawText(abbreviate(score3), 0, -40, 20, "yellow")
end

imma try it in a different folder to prevent things from breaking

its not doing anything I will show you the entire code

  Points = storage.get("point")
  BaseUPG1 = storage.get("Base_UPG1")
  ValeurClic = storage.get("Point_Gain")
  BaseBoost = storage.get("formula_v1")
  MultiBoost = storage.get("formula_v2")
  MultiUPG1 = storage.get("Multi_UPG1")
  MultiUPG1Lvl = storage.get("Multi_UPG1Lvl")
  MultiUPG2Lvl = storage.get("MultiUPG2_Lvl")
  MultiUPG2 = storage.get("MultiUPG2")
  
  abbreviate = function(Points)
  if Points < 1000 then return floor(Points) end
  
  // Standard English abbreviations: k, Million, Billion, Trillion...
  local units = ["k", "M", "B", "T", "Qd", "Qi", "Sx", "Sp"]
  local index = -1
  local value = Points

  while value >= 1000 and index < units.length - 1
    value /= 1000
    index += 1
  end

  // Example: 1.285M
  return (floor(value * 1000) / 1000) + units[index]
end  
  
  if Points == undefined then Points = 0 end
  if BaseUPG1 == undefined then BaseUPG1 = 10 end
  if ValeurClic == undefined then ValeurClic = 1 end
  if MultiUPG1 == undefined then MultiUPG1 = 250 end
  if MultiUPG1Lvl == undefined then MultiUPG1Lvl = 0 end
  if BaseBoost == undefined then BaseBoost = 0 end
  if MultiBoost == undefined then MultiBoost = 1 end
  if MultiUPG2 == undefined then MultiUPG2 = 10000 end
  if MultiUPG2Lvl == undefined then MultiUPG2Lvl = 0 end
  

  
  msg = ""
  msgTimer = 0

  Button = class
    constructor = function(x, y, width, height, id)
      this.x = x
      this.y = y
      this.width = width
      this.height = height
      this.id = id
      this.oldW = width
      this.oldH = height
    end
  end
  
  buttons = []
  buttons.push(new Button(-175, -75, 45, 45, "1"))
  buttons.push(new Button(175, 70, 45, 45, "2"))
  buttons.push(new Button(150, -75, 100, 40, "3")) 
  buttons.push(new Button(150, -30, 100, 40, "4")) 
  buttons.push(new Button(150, 15, 100, 40, "5"))
end


update = function() 
  if msgTimer > 0 then msgTimer -= 1 end
  
  value = Points
  
  ValeurClic = floor((1 + BaseBoost) * MultiBoost)
  
  for b in buttons
    local targetW = b.width
    local targetH = b.height
    
    if checkRectMouseHover(b.x, b.y, b.width, b.height) then
      targetW = b.width + 15
      targetH = b.height + 15
      
      if b.id == "2" and mouse.press then 
        Points += ValeurClic 
      end
      
      if b.id == "1" and mouse.press then
        storage.set("point", Points)
        storage.set("Base_UPG1", BaseUPG1)
        storage.set("Point_Gain", ValeurClic)
        storage.set("Multi_UPG1", MultiUPG1)
        storage.set("Multi_UPG1Lvl", MultiUPG1Lvl)
        storage.set("formula_v1", BaseBoost)
        storage.set("formula_v2", MultiBoost)
        storage.set("MultiUPG2_Lvl", MultiUPG2Lvl)
        storage.set("Multi_UPG2", MultiUPG2)
        msg = "GAME SAVED!"
        msgTimer = 120
      end

      if b.id == "3" and mouse.press then 
        if Points >= BaseUPG1 then
          Points -= BaseUPG1
          BaseBoost += 1
          BaseUPG1 = floor(BaseUPG1 * 1.25)
          msg = "UPGRADE BOUGHT!"
          msgTimer = 120
        end
      end
      
       if b.id == "4" and mouse.press then
        if Points >= MultiUPG1 and MultiUPG1Lvl < 50 then
          Points -= MultiUPG1
          MultiUPG1Lvl += 1
          MultiBoost = (MultiBoost * 1.5)
          MultiUPG1 = floor(MultiUPG1 * 2)
      end
    end
        if b.id == "5" and mouse.press then
          if Points >= MultiUPG2 and MultiUPG2Lvl < 10 then
            Points -= MultiUPG2
            MultiUPG2Lvl += 1
            MultiUPG2 = (MultiUPG2 * 10)
            MultiBoost = (MultiBoost * 2)
          end
        end
      end
  

    if b.oldW < targetW then b.oldW += 1
    elsif b.oldW > targetW then b.oldW -= 1
    end
    
    if b.oldH < targetH then b.oldH += 1
    elsif b.oldH > targetH then b.oldH -= 1
    end
  end
end

  draw = function()
    screen.clear("rgb(85,198,255)")
    screen.drawText("POINTS: " + Points, -150, 75, 20, "Black")
  
      
  if msgTimer > 0 then
    screen.drawText(msg, 0, 120, 15, "rgb(255,255,255)")
  end
  
  for b in buttons
    if b.id == "2" then
      screen.drawSprite("point_upgrades", b.x, b.y, b.oldW, b.oldH)
    elsif b.id == "1" then
      screen.drawSprite("save", b.x, b.y, b.oldW, b.oldH)
    elsif b.id == "3" then
      screen.fillRect(b.x, b.y, b.oldW, b.oldH, "orange")
      screen.drawRect(b.x, b.y, b.oldW, b.oldH, "white")
      screen.drawText("+1 BaseGain: " + BaseUPG1, b.x, b.y, 12, "white")
    elsif b.id == "4" and BaseUPG1 >= 78 and MultiUPG1Lvl < 50 then
      screen.fillRect(b.x, b.y, b.oldW, b.oldH, "orange")
      screen.drawRect(b.x, b.y, b.oldW, b.oldH, "white")
      screen.drawText("1.5x Multiplier: " + MultiUPG1, b.x, b.y, 12, "white")
    elsif b.id == "5" and MultiUPG1 >= 1000 and MultiUPG2Lvl < 10 then
      screen.fillRect(b.x, b.y, b.oldW, b.oldH, "orange")
      screen.drawRect(b.x, b.y, b.oldW, b.oldH, "white")
      screen.drawText("2x Multiplier:" + MultiUPG2, b.x, b.y, 12, "white")
    end
  end
end```

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community