generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: show as integer help?

Previous Thread :: Next Thread 
qdhxx is not online. qdhxx
Joined: 02 Jul 2010
Total Posts: 56658
27 Jun 2015 11:16 AM
I have this 4-line script and I want "h.Enemy.Health" to be shown as an integer, how do I make it ignore everything after the dot? example: show 1.336 as 1, and show 42.76 as 42

1 h = script.Parent
2 while true do
3 h.Name = script.Parent.Enemy.Folder.NAME.Value.. " [LVL" ..script.Parent.Enemy.Folder.LVL.Value.."] HP: " .. h.Enemy.Health .. "/" .. h.Enemy.MaxHealth
wait(0)
4 end




mfw http://www.roblox.com/face-item?id=241134674 | successful https://youtu.be/zIfy6q0lM2Q |
Report Abuse
DoTehAlan is not online. DoTehAlan
Joined: 13 Feb 2011
Total Posts: 626
27 Jun 2015 11:17 AM
Look up math in the roblox wiki



Everyone has potential, but they have to fulfill it to succeed.
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
27 Jun 2015 11:17 AM
math.ceil or math.floor
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
27 Jun 2015 11:17 AM
math.floor(n)
Report Abuse
qdhxx is not online. qdhxx
Joined: 02 Jul 2010
Total Posts: 56658
27 Jun 2015 11:24 AM
"math.floor(n)"

thanks a lot this works perfectly

now I have another question, what if I wanna show only one digit after the dot?
like 42.535 becomes 42.5

that would look cooler


mfw http://www.roblox.com/face-item?id=241134674 | successful https://youtu.be/zIfy6q0lM2Q |
Report Abuse
qdhxx is not online. qdhxx
Joined: 02 Jul 2010
Total Posts: 56658
27 Jun 2015 11:28 AM
brr


mfw http://www.roblox.com/face-item?id=241134674 | successful https://youtu.be/zIfy6q0lM2Q |
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
27 Jun 2015 11:30 AM
math.ceil would actually be better for health as 0.3 would show up as 0 O_O


As for making it show to the 1 decimal place, I don't have the brains to do math right now, so you could manipulate it as a string:

local n = 42.309

n = tonumber(tostring(n):sub(1, select(2, tostring(n):find("."))+1))



*Hopes I had the brain to actually do that correctly*
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
27 Jun 2015 11:32 AM
dp1 = string.match(123.45, "%d+%.%d")
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
27 Jun 2015 11:33 AM
I... Hate... String... Patterns...


They always show up and overpower the old fashion brain-required way.
Report Abuse
qdhxx is not online. qdhxx
Joined: 02 Jul 2010
Total Posts: 56658
27 Jun 2015 11:37 AM
i'm not good with strings how do I apply these to h.Enemy.Health as I wrote in the original script? thx in advance


mfw http://www.roblox.com/face-item?id=241134674 | successful https://youtu.be/zIfy6q0lM2Q |
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
27 Jun 2015 11:43 AM
I rewrote the function a little to prevent breaking.
http://pastebin.com/psNz8v3N
----------------------
^ DP(Number, Decimal Places)
Report Abuse
qdhxx is not online. qdhxx
Joined: 02 Jul 2010
Total Posts: 56658
27 Jun 2015 11:59 AM
it's problematic, if I put DP(h.Enemy.Health, 1) instead of h.Enemy.Health then it says I'm trying to concatenate something that doesn't exist

if I just put it there above it it does nothing

how am I supposed to use it?


mfw http://www.roblox.com/face-item?id=241134674 | successful https://youtu.be/zIfy6q0lM2Q |
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
27 Jun 2015 12:01 PM
What is h.Enemy.Health?
Report Abuse
qdhxx is not online. qdhxx
Joined: 02 Jul 2010
Total Posts: 56658
27 Jun 2015 12:04 PM
The number of health in the RPG monster's humanoid named "Enemy"

h itself is the whole model of the monster


mfw http://www.roblox.com/face-item?id=241134674 | successful https://youtu.be/zIfy6q0lM2Q |
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
27 Jun 2015 12:04 PM
string.format('%.1f',thingyThingHealth)
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
27 Jun 2015 12:05 PM
I gave you the reason why earlier.

DP(h.Enemy.Health, 1) or DP(h.Enemy.Health, 0)
Report Abuse
qdhxx is not online. qdhxx
Joined: 02 Jul 2010
Total Posts: 56658
27 Jun 2015 12:08 PM
@eLunate thanks it works perfectly and not only that, it's all in just one line of code, making it very convenient and cool. thanks a lot!

@epicbreaker thanks for your time


mfw http://www.roblox.com/face-item?id=241134674 | successful https://youtu.be/zIfy6q0lM2Q |
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image