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 » Scripting Helpers
Home Search
 

Little string manipulation help, please?

Previous Thread :: Next Thread 
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
16 Aug 2012 08:31 AM
So, I have a string like this: 12.5 (NOT A NUM-VALUE, IT'S A STRING)
How could I take out the '.5' so I have

var1=12
var2=0.5 --or .5, that 0 doesn't matter.

I know it's something like string.find, or string.gmatch, I just need some help, as I am not very good with String Manipulation.

--TehChikenHater ლ(ಠ_ಠლ)
Report Abuse
IPOOPONU39 is not online. IPOOPONU39
Joined: 15 Aug 2012
Total Posts: 51
16 Aug 2012 08:37 AM
[ Content Deleted ]
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
16 Aug 2012 08:39 AM
lolwut.

You fail bro.

--TehChikenHater ლ(ಠ_ಠლ)
Report Abuse
IPOOPONU39 is not online. IPOOPONU39
Joined: 15 Aug 2012
Total Posts: 51
16 Aug 2012 08:43 AM
[ Content Deleted ]
Report Abuse
iAdobe is not online. iAdobe
Joined: 22 May 2011
Total Posts: 367
16 Aug 2012 08:46 AM
local string = "12.5"

local newstring = string:find("12",1,true)
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
16 Aug 2012 08:49 AM
local var = "12.5"

var = tonumber(var)
local var1 = math.floor(var)
local var2 = (var-var1)

print(var1, var2)
> 12 0.5
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
16 Aug 2012 08:54 AM
Wow Crazyman32, I gotta give props for thinking of that. Thanks man. :3

-> Siggy pooped by the power of Ponies <-
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
16 Aug 2012 08:54 AM
no probs, I've had to do it before.
Report Abuse
awsumpwner27 is not online. awsumpwner27
Joined: 03 Sep 2011
Total Posts: 4389
16 Aug 2012 08:55 AM
x = "12.5"
a,b = string.find(x, "%p%d")
print(string.sub(x,1,a-1))
Report Abuse
awsumpwner27 is not online. awsumpwner27
Joined: 03 Sep 2011
Total Posts: 4389
16 Aug 2012 08:56 AM
I was thinking of that solution too, but mine works just as well. Good luck with whatever you're doing.
Report Abuse
awsumpwner27 is not online. awsumpwner27
Joined: 03 Sep 2011
Total Posts: 4389
16 Aug 2012 08:57 AM
Oh, you want the ".5" too?

Lemme figure it out for fun. Gimme a moment.
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
16 Aug 2012 08:58 AM
Actual regex string patterns will do the trick too, but straight-up math is actually faster for the computer to figure out
Report Abuse
awsumpwner27 is not online. awsumpwner27
Joined: 03 Sep 2011
Total Posts: 4389
16 Aug 2012 08:58 AM
x = "12.5"
a,b = string.find(x, "%p%d")
print(string.sub(x,1,a-1), "0"..string.sub(x,a))

>12 0.5
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
16 Aug 2012 08:59 AM
Thanks!

If anyone would like to know what i'm doing, i'm creating a timer to display how long someone has held a checkpoint or whatever you want to call it. :c
And, I needed to do that, because if I have a number such as:

1230 (In seconds) if I divide that by 60, I get

20.5

So, 20 minutes, and 30 seconds, and I needed to beable to extract that 0.5, which is basically the decimal out. If you now know that this is what it's for, and think there is a better solution, feel free to post it.

-> Siggy pooped by the power of Ponies <-
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
16 Aug 2012 09:01 AM
Btw, if you're trying to keep good time, I suggest tracking actual time:


local start = time()
while (IsOnCheckpointOrWhatever) do
local fullTime = (time()-start)

-- fullTime is how long they've been there

wait()
end
Report Abuse
awsumpwner27 is not online. awsumpwner27
Joined: 03 Sep 2011
Total Posts: 4389
16 Aug 2012 09:01 AM
It makes sense that your solution is faster, I just wanted to do something I haven't before. Again, good luck to all of you in whatever you do.
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
16 Aug 2012 09:07 AM
The second one you gave me Crazyman32, will work much better for my script. Thank you so much! :D

-> Siggy pooped by the power of Ponies <-
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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