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
|
  |
| 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 |
|
|
| |
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
| |
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 27 Jun 2015 11:32 AM |
| dp1 = string.match(123.45, "%d+%.%d") |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
| |
|
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
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 27 Jun 2015 12:04 PM |
| string.format('%.1f',thingyThingHealth) |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|