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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Simple string manipulation problem

Previous Thread :: Next Thread 
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
14 Jun 2015 11:15 PM
What sort of pattern should I use if I were looking for two numbers linked by an "=" sign? My game's items each have Ids, and I want the string to only have the ItemId occurence in it once. However, if the ItemId is 1, it conflicts with the other Ids that end in 1.

for Index, Item in next, Items do
if not Returned:match(Item.Name .. "=%d+") then
local ItemId = tonumber(Item.Name)
if ItemId then
local Value = CheckEquipped(Equipped, ItemId) and Item.Value - 1 or Item.Value
if Value > 0 then
Returned = Returned .. (ItemId .. "=" .. Value) .. (Index == #Items and "" or ",")
end
end
end
end

The Item's name is a number (it is the ItemId of it also). The pattern is 'Item.Name .. "=%d+"', but if the Item name is 1 and an ItemId of 101 already exists in the string, it will match the 1 on the end and the rest of the sequence. How do I get around this?

The ItemIds and value pairs are linked together by a comma delimiter.
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
14 Jun 2015 11:18 PM
Example (let's say we have this so far in the loop)

Returned = "Currency=0,101=1,201=1,251=1,301=1,"

But now the next ItemId is 1. How would I ignore all these occurrences of 1s in the other ItemIds?
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
14 Jun 2015 11:22 PM
for v in string.gmatch(strin, "(%w)%s?=%s?(%d)")do
print(v)
end
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
14 Jun 2015 11:34 PM
local split = function(str, delim)
local tab = {}
for v in string.gmatch(str, "["..delim.."]+")do
table.insert(tab, v)
end
return tab
end

local current = "sample=1,5=2,10"

local sample = split(current, "=")

local numbers = {}

for _, v in pairs(sample)do
table.insert(numbers, split(v, ","))
end
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
14 Jun 2015 11:43 PM
I wasn't really clear. I want to find if the pattern 'Item.Name .. "=%d+"' exists in the string, but if a number directly precedes that pattern, ignore it.
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
14 Jun 2015 11:45 PM
Make a more visual approach to me. I can't understand you. Just use tables or something.
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
15 Jun 2015 12:02 AM
Inside the player, there is a folder named "Inventory". The children of this folder are IntValues have integer names that represent an ItemId. The value of these IntValues represent the quantity of that ItemId in the player. What I want to do is take this information and convert it into a string with a format of "%s+(IntValue.Name)=%d+(IntValue.Value)", with a comma as a delimiter to separate these entries. The problem is that I want to make sure the ItemId
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
15 Jun 2015 12:05 AM
Post continuing:

doesn't occur more than once in the string. So I set up a conditional to see if that format already exists when I'm looping through the children to convert the inventory, but that conditional catches the first ItemId (which is 1) and prevents it from being added to the string because other ItemIds also end in 1 (and are already in that string).
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
15 Jun 2015 12:08 AM
So when I want to make sure this string "Currency=0,101=1,201=1" doesn't contain the pattern "1=%d+", the first thing it will match is the "1=1" following the 0 in the ItemId "101" to the "," before the next ItemId.
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
15 Jun 2015 12:18 AM
Don't use XValues.

Use tables. or better yet a thing you can serialize to save. Now you can save all your stuff in your script and use remote events.

NEVER USE XVALUES!


local Item = {}

Item.new = function(name,id)
local this = {
Name = name;
Id = id
}

this.Serialize = function(self)
local out = {}
for _, v in pairs(self)do
if(type(v) ~= "function")then
table.insert(out, v.Name..","..type(v.Id)..","..v.Id)
end
return out
end
end

return this
end

-- local table = {"name,value", etc.}
Item.Deserialize = function(self, input)

local item = Item.new()
for _, v in pairs(input)do
local field = {}
for n in string.gmatch("[,]+")do
table.insert(field, n)
end
item[field[1]] = field[2] == "number" and tonumber(field[3]) or tostring(field[3])
end

end

return Item
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
15 Jun 2015 12:27 AM
Thanks, I will use that idea to come up with something.
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