Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to separate a string into Data?

Asked by 5 years ago
Edited 5 years ago

I created a save/load script for Parts. Now i have to seperate the data to load it again how whould i do this?

Data format: Name: [Part], Position: [0, 0, 0] , Color: [0, 0, 0] , Material: [Enum.Material.Plastic]

how would you separate this to something like local Name,local Position, local Color and local Material?

I thought about doing something like string.sub

How I store the data:

function generateDataTable(player)
    local dataTable = {} 
    for i,v in pairs(game.Workspace.TestFolder:GetChildren()) do 
        table.insert(dataTable, ("Name: ["..tostring(v.Name).."], Position: ["..tostring(v.Position).."] , Color: ["..tostring(v.Color).."] , Material: ["..tostring(v.Material).."]"))
    return dataTable
end
0
It depends on how you`re saving the parts... can you please post the script? Leamir 3138 — 5y
0
I added the script to the question MageMasterHD 261 — 5y
0
I think the error is on the saving script Leamir 3138 — 5y
0
there is no error i just want to get the saved data separated into pieces MageMasterHD 261 — 5y
View all comments (3 more)
0
I want this: Name: [Part], Position: [0, 0, 0] , Color: [0, 0, 0] , Material: [Enum.Material.Plastic] to be something like this: local Name = ... local Position = ... local Color = ... local Material = ... MageMasterHD 261 — 5y
0
You don't need to tostring the name, it's already a string. User#19524 175 — 5y
0
ok but how do i seperate the data MageMasterHD 261 — 5y

1 answer

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago

Hello, MageMasterHD!

I think you don't know lots about tables and dictionaries, that I think is what you want to do with your data, so I had to create it:

local dataTable = {} 
for i,v in pairs(game.Workspace.TestFolder:GetChildren()) do 
    table.insert(dataTable, {["Name"] = v.Name, ["Position"] = v.Position, ["Color"] = v.Color, ["Material"] = v.Material}) --Created a Dictonary of the values
end

Now you can do:

dataTable[1]["Name"] --This will give the name of the object 1
dataTable[1]["Position"] --This will give the Vector3 of the object 1 position
dataTable[1]["Color"] --This will give the Color3 of the object 1

By Object 1 i'm telling about the object with index 1 (first object of the for loop)

Useful Links:

https://developer.roblox.com/articles/Table#Dictionaries

Hope this helps

Good Luck with your games

0
thx you helped me a lot MageMasterHD 261 — 5y
Ad

Answer this question