Saltearse al contenido

Creating a smart number abbreviation system for lifting sim games

Esta página aún no está disponible en tu idioma.

💡 Having trouble with Scratch block assembly? Don’t know how to implement code logic? 🚀 Get Help Now

FG

FitnessGameDev

Posted on January 25, 2024 • Advanced

💪 Smart number abbreviation for lifting simulator

Hey everyone! I’m developing a lifting simulator game where muscle strength values grow exponentially. The problem is my current abbreviation system always shows 3 decimal places, which looks messy and unnecessary.

What I want to achieve:

  • 106667 → 106.6k muscle (1 decimal place)
  • 10667 → 10.66k muscle (2 decimal places)
  • 1067 → 1.067k muscle (3 decimal places)

Basically, I need dynamic decimal places based on the number size. The current system showing “106.667k” looks unprofessional. Any ideas for a cleaner approach? 🤔

MA

MathWizard_Alex

Replied 3 hours later • ⭐ Best Answer

Perfect question @FitnessGameDev! This is a common challenge in idle/incremental games. Here’s a smart abbreviation system that dynamically adjusts decimal places:

🧮 Dynamic Abbreviation Flow

Here’s how the smart abbreviation system works:

flowchart TD A[📊 Input Number] --> B{Number ≥ 100,000?} B -->|Yes| C[Divide by 1000<br/>1 decimal place] B -->|No| D{Number ≥ 10,000?} D -->|Yes| E[Divide by 1000<br/>2 decimal places] D -->|No| F{Number ≥ 1,000?} F -->|Yes| G[Divide by 1000<br/>3 decimal places] F -->|No| H[No abbreviation<br/>Show full number] C --> I[Round to 1 decimal] E --> J[Round to 2 decimals] G --> K[Round to 3 decimals] I --> L[Add 'k' suffix] J --> L K --> L H --> M[Add unit only] L --> N[📱 Display Result] M --> N style A fill:#e1f5fe style N fill:#e8f5e8 style C fill:#fff3e0 style E fill:#f3e5f5 style G fill:#fce4ec

🔧 Step 1: Create the Smart Abbreviation Function

First, create a custom block that handles dynamic decimal places:

    define smart abbreviate (number) (unit)
if <(number) ≥ [100000]> then
set [temp v] to ((number) / [1000])
set [decimal places v] to [1]
else
if <(number) ≥ [10000]> then
set [temp v] to ((number) / [1000])
set [decimal places v] to [2]
else
if <(number) ≥ [1000]> then
set [temp v] to ((number) / [1000])
set [decimal places v] to [3]
else
set [temp v] to (number)
set [decimal places v] to [0]
end
end
end
  

📐 Step 2: Precision Rounding System

Add precise rounding based on decimal places:

    // Continue from previous block
set [multiplier v] to ([10^ v] of (decimal places))
set [rounded v] to ((round ((temp) * (multiplier))) / (multiplier))

if <(number) ≥ [1000]> then
set [result v] to (join (join (rounded) [k ]) (unit))
else
set [result v] to (join (rounded) (unit))
end
  

🎮 Step 3: Implementation Examples

Here’s how to use it in your lifting simulator:

    // Display muscle strength
when flag clicked
smart abbreviate (muscle strength) [ muscle] :: custom
set [muscle display v] to (result)

// Display money/coins
smart abbreviate (player money) [ coins] :: custom
set [money display v] to (result)

// Display experience points
smart abbreviate (total xp) [ XP] :: custom
set [xp display v] to (result)
  

🚀 Step 4: Advanced Features

For even larger numbers, extend to millions and billions:

    define mega abbreviate (number) (unit)
if <(number) ≥ [100000000]> then
set [temp v] to ((number) / [1000000])
set [suffix v] to [M]
set [decimal places v] to [1]
else
if <(number) ≥ [10000000]> then
set [temp v] to ((number) / [1000000])
set [suffix v] to [M]
set [decimal places v] to [2]
else
if <(number) ≥ [1000000]> then
set [temp v] to ((number) / [1000000])
set [suffix v] to [M]
set [decimal places v] to [3]
else
// Use previous k abbreviation logic
smart abbreviate (number) (unit) :: custom
set [result v] to (result)
stop [this script v]
end
end
end

// Apply rounding and formatting
set [multiplier v] to ([10^ v] of (decimal places))
set [rounded v] to ((round ((temp) * (multiplier))) / (multiplier))
set [result v] to (join (join (join (rounded) (suffix)) [ ]) (unit))
  

✨ Step 5: Real-time Display Updates

Keep your displays updated automatically:

    when flag clicked
forever
mega abbreviate (muscle strength) [muscle] :: custom
set [muscle text v] to (result)

mega abbreviate (bench press max) [lbs] :: custom
set [bench text v] to (result)

mega abbreviate (total earnings) [coins] :: custom
set [money text v] to (result)

wait [0.1] seconds
end
  

This system will give you clean, professional-looking numbers that scale perfectly with your game’s progression! 💪

FG

FitnessGameDev

Replied 45 minutes later

@MathWizard_Alex This is absolutely perfect! 🎉 The dynamic decimal system works flawlessly!

I implemented it and now my numbers look so much cleaner. One quick question - how would I handle negative numbers for things like debt or penalties?

IG

IdleGameExpert

Replied 2 hours later

@FitnessGameDev Great question! For negative numbers, just add this at the beginning of your function:

    define smart abbreviate with negatives (number) (unit)
if <(number) < [0]> then
set [is negative v] to [true]
set [number v] to ((0) - (number))
else
set [is negative v] to [false]
end

// ... rest of abbreviation logic ...

// At the end, add minus sign if needed
if <(is negative)> then
set [result v] to (join [-] (result))
end
  

This handles debt, penalties, or any negative values perfectly! 💰

VB

Vibelf_Community

Pinned Message • Moderator

🚀 Ready to Build More Advanced Game Systems?

Excellent discussion on number formatting! For developers looking to create even more sophisticated idle/incremental games, our community can help you implement:

  • 🏋️ Progressive training systems
  • 📈 Exponential growth algorithms
  • 💎 Prestige and rebirth mechanics
  • 🎯 Achievement unlock systems

📚 Related Topics

Want to master advanced game mathematics and progression systems? Get personalized guidance from our expert tutors in the Vibelf app!