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: string to vector3 challenge

Previous Thread :: Next Thread 
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
23 Aug 2015 12:01 PM
Must support all number representations.

1
1.2
-2
2e4
3e+7
0x0111
etc
etc

The numbers will be seperated with a single space character.

Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
23 Aug 2015 12:10 PM
StringToVector3 = function(s)
local X,Y,Z
for word in s:gmatch("[^%s]+") do
if not X then
X = tonumber(word)
elseif not Y then
Y = tonumber(word)
elseif not Z then
Z = tonumber(word)
end
end
if X and Y and Z then
return Vector3.new(X,Y,Z)
end
return nil
end
Report Abuse
lupine is not online. lupine
Joined: 24 Jun 2008
Total Posts: 3561
23 Aug 2015 12:14 PM
Not difficult, just too much work. I thought about how I'd make it, I just didn't do any typing.
Report Abuse
ShungTzu is not online. ShungTzu
Joined: 14 Jun 2014
Total Posts: 959
23 Aug 2015 12:18 PM
What about commas? The axes of all the Vector3s I see in Roblox are separated by commas.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
23 Aug 2015 12:23 PM
...

THE STRING NUMBERS ARE SEPERATED BY A SINGLE SPACE.

WTF is so hard to understand?
Report Abuse
ShungTzu is not online. ShungTzu
Joined: 14 Jun 2014
Total Posts: 959
23 Aug 2015 12:42 PM
That would be easier. Here's one that actually works with real Vector3s.

prp='-179.879, 85.094, 179.895'
local cells={}
for i=1,2 do
local comma=string.find(prp,',')
local cell=string.sub(prp,1,tonumber(comma-1))
prp=string.sub(prp,comma+1)
table.insert(cells,cell)
end
prp=tonumber(prp)
table.insert(cells,prp)
prp=Vector3.new(unpack(cells))
print(prp)

Crude, yes, but yours doesn't even work with your imaginary, non-comma-having Vector3s.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
23 Aug 2015 12:50 PM
Let me try to explain the error of your ways.

1. Please wait 3-5 years before coming onto forums.

2. How you encode a Vector3 into a string doesn't matter at all, the challenge is to convert strings where numbers are seperated by a space back into Vector3.
Report Abuse
ShungTzu is not online. ShungTzu
Joined: 14 Jun 2014
Total Posts: 959
23 Aug 2015 12:56 PM
Okay, I take that back, it does work. ' didn't copy the whole function and got the return inside the loop.

Here

StringToVector3 = function(s)
local X,Y,Z
for word in s:gmatch("[^%s^,]+") do
print(word)
X = tonumber(word)
Y = tonumber(word)
Z = tonumber(word)
end
if X and Y and Z then
return Vector3.new(X,Y,Z)
end
return nil
end

now it works in the real world.
Report Abuse
chimmmihc is not online. chimmmihc
Joined: 24 Jul 2014
Total Posts: 2420
23 Aug 2015 12:59 PM
I like how chimm asks a hard question nobody answers the question for ten minutes and as soon as he gives an answer everyone is like "OH I KNEW THAT I JUST DIDN'T WANT TO DO IT"

Deflate your ego guys.
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
23 Aug 2015 01:04 PM
function stringToVector(s)
local allNums = {}
for num in s:gmatch("[^%s]+") do
allNums[#allNums + 1] = num
end
return Vector3.new(unpack(allNums))
end

print(stringToVector("3e7 2e+2 -.4"))

-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
23 Aug 2015 01:04 PM
"chimmmihc" totally not an alt

~Upload code to codepad-dot-org with Lua syntax highlighting to preserve indentation and make it easier to read!~
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
23 Aug 2015 01:07 PM
who is chimmmihc
Report Abuse
chimmmihc is not online. chimmmihc
Joined: 24 Jul 2014
Total Posts: 2420
23 Aug 2015 01:09 PM
I'm garybyte

http://www.roblox.com/Forum/ShowPost.aspx?PostID=171821726

It a joke name change
Report Abuse
ClownStash is not online. ClownStash
Joined: 08 Aug 2015
Total Posts: 190
23 Aug 2015 01:11 PM
local stv3=function(s)
local a={}
for i in s:gmatch('[^%s]+') do
a[#a+1]=tonumber(i)
if #a>3 then break end
end
return Vector3.new(unpack(a))
end
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
23 Aug 2015 01:15 PM
local function StringToVector3(str)
local x, y, z = str:match("(%S+)%s+(%S+)%s+(%S+)")
return Vector3.new(tonumber(x), tonumber(y), tonumber(z))
end

Yay I win

~Upload code to codepad-dot-org with Lua syntax highlighting to preserve indentation and make it easier to read!~
Report Abuse
ShungTzu is not online. ShungTzu
Joined: 14 Jun 2014
Total Posts: 959
23 Aug 2015 01:27 PM
Ego? What about his ego? You can't assume that everyone sees a post as soon as it goes up. It's not like we have events in our brains that fire as soon as chimmihc clicks Post. I saw his response the first time I clicked on the thread, asked a simple question, and look at his response to it.
Report Abuse
ShungTzu is not online. ShungTzu
Joined: 14 Jun 2014
Total Posts: 959
23 Aug 2015 01:55 PM
Anyway, I'll go ahead and apologize. I was angered by his response to me and, in haste, said something not true and posted something that doesn't work.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Aug 2015 03:27 PM
local x, y, z = str:match("([^,]+), ([^,]+), ([^,]+)");
return Vector3.new(tonumber(x), tonumber(y), tonumber(z));
Report Abuse
robloxer8282 is not online. robloxer8282
Joined: 25 Dec 2012
Total Posts: 819
23 Aug 2015 03:32 PM
I dont get it
Report Abuse
ImageLabel is not online. ImageLabel
Joined: 08 Dec 2012
Total Posts: 428
23 Aug 2015 03:35 PM
just an fyi, Vector3 will automatically convert your strings to numbers


local str = "1e, 1e, 1e"
local x, y, z = str:match("([^,]+), ([^,]+), ([^,]+)");

print(Vector3.new(x,y,z) == Vector3.new());
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Aug 2015 03:37 PM
Yeah but your example code doesn't make sense lol
Report Abuse
ImageLabel is not online. ImageLabel
Joined: 08 Dec 2012
Total Posts: 428
23 Aug 2015 03:40 PM
Vector3.new("0","0","0") == Vector3.new(0,0,0)*

Report Abuse
TickerOfTime is not online. TickerOfTime
Joined: 02 Sep 2012
Total Posts: 2030
23 Aug 2015 04:21 PM
local Vector3String='1e3 -38.380 0x0111'
local X,Y,Z=Vector3String:match'(.-) (.-) (.-)' or error'Invalid string'
local FinalVector3=Vector3.new(X,Y,Z)
Report Abuse
ShungTzu is not online. ShungTzu
Joined: 14 Jun 2014
Total Posts: 959
23 Aug 2015 05:17 PM
Can this get any shorter?

stringtovalue=function(s)
local cells={}
for cell in s:gmatch("[^%s^,^{^}]+") do
table.insert(cells,cell)
end
if #cells==3 then
return Vector3.new(unpack(cells))
elseif #cells==2 then
return Vector2.new(unpack(cells))
elseif #cells==4 then
print('uDim')
return UDim2.new(unpack(cells))
elseif #cells==6 then
local v1=Vector3.new(cells[1],cells[2],cells[3])
local v2=Vector3.new(cells[4],cells[5],cells[6])
return Ray.new(v1,v2)
elseif #cells==12 then
return CFrame.new(unpack(cells))
end
return nil
end
Report Abuse
ClownStash is not online. ClownStash
Joined: 08 Aug 2015
Total Posts: 190
24 Aug 2015 06:35 AM
stringtovalue=function(s)
local cells={}
local t={[3]=Vector3.new,[2]=Vector2.new,[4]=UDim2.new,[12]=CFrame.new}
for cell in s:gmatch("[^%s^,^{^}]+") do cells[#cells+1]=cell end
return t[#cells](unpack(cells)) or nil
end


Try this. Not 100% sure if it will work.
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