|
| 27 Mar 2015 11:37 PM |
I've realized how little I know about string patterns. My issue: I need to match the first set of new and create and the second set of new and create in different iterations. How can I separate them via string pattern operators?
str=[[ new ScreenGui in game.StarterGui set Name "Hi" create new Frame in $-1 set name "FrameThing" create ]]
for match in str:gmatch("(new.+create)") do print("match: "..match) end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Mar 2015 11:39 PM |
My idea of handling this was a bite different (using a stack essentially) but you probably want:
new%s+(.-)create |
|
|
| Report Abuse |
|
|
|
| 27 Mar 2015 11:42 PM |
Seeing as how it was your idea to do it this way, I'd love to see how you wanted it done. I'm just trying to see how I'd piece this all together. :) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Mar 2015 11:46 PM |
Well my idea was something like: (quotes mainly for strings that have spaces, but you can handle this how you like)
new ScreenGui in game.StareterGui set Name Hi create
The first instruction would add the instance to the end of the table, the second instruction (set) would use the last pushed instance to edit and create would finally actually really just parent it.
So adding this: new TextLabel in $-1 set Name K create
the $-1 means the last item from the stack ($-2 = second to last item, $1 = first item, $2 = second item) so that would use the ScreenGui you created. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Mar 2015 11:51 PM |
I actually had an idea to have all instructions have an optional last arg. that is an offset (default would be -1, the last pushed) but anyways:
maybe you don't need the "in" idk up to you new ScreenGui game.StarterGui set Name "Hello Friends" create
new Frame $-1 set Name Frameo set Size UDim2 "0 20 0 20" set Position UDim2 "0.5 -10 0.5 -10" create
new Frame $-2 set Name Frameo2 set Size UDim2 "0 10 0 10" create
The $-2 will get the ScreenGui since the new frame we created above that one (the first frame created) will now be the last pushed one. |
|
|
| Report Abuse |
|
|
|
| 27 Mar 2015 11:52 PM |
Continuing off of cnt's post, you are going through this line by line, right? Using a stack would be a good idea, especially if you stick with $-n alias. I would also recommend using the 'as' keyword to set an alias in the 'new' command:
new ScreenGui in game.StarterGui as Gui_Master ... create
new TextLanel in Gui_Master --- create
I know this is your own personal project, so I won't write out any code, but if you'd like a little sample of what I would do, just let me know. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 27 Mar 2015 11:53 PM |
| Oh yeah I like that "as" idea, that would be cool |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:01 AM |
That's a great idea! Thank you guys for helping me out with this (: I'll show you guys what I have after I fix a small bug.
My pattern to find the Parent is as follows: parent=match:match("%s*%a+%s+in%s+(%a+)") or match:match("%s*%a+%s+in%s+(%$%-%d+)")
However, if it is game.StarterGui for example, it only returns "game" as the punctuation character interferes with the pattern. How can I fix this so it won't break even if the parent is game.StarterGui.ScreenGui.Frame.Frame.Textlabel and so on? |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:03 AM |
local line = "create ScreenGui in game.StarterGui as Gui_Main" local Class, ParentStr = line:match("create%s+(%w+)%s+in%s+(%S+)") local Alias = line:match("as%s+([%w_])+$")
print( Class, ParentStr, Alias ) |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:04 AM |
local Alias = line:match("as%s+([%w_]+)$")
+ was supposed to be inside the parenthesis. Oops. :P Do you understand all that? I'd be more than happy to explain it. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Mar 2015 12:10 AM |
| You should probably use %b'' with it in a set or something so if it is in quotes you can get it. Unless this is gonna be quoteless (which would make things much easier) |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:12 AM |
I suppose some items could have a space in their name, couldn't they? Surrounding the name in quotes would probably be his best bet if spaces are allowed. Otherwise he can just use %S+. |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:17 AM |
Note done yet, but this is what I have. Tell me what you think :) (I'm sure the string patterns are horribly inefficient, but I'll fix them eventually.)
objects={} aliases={}
str=[[ new ScreenGui in game.StarterGui as Ancestor set Name "Hi" create new Frame in $-1 set name "FrameThing" create ]]
function getAlias(input) for i,v in pairs(aliases) do if i==input then return v end end end
for match in str:gmatch("new%s+(.-)create") do class=match:match("%s*(%a+)%s+in") parent=match:match("%s*%a+%s+in%s+(%S+)") or match:match("%s*%a+%s+in%s+(%$%-%d+)") or getAlias("%s*%a+%s+in%s+as%s+(%w+)") alias=match:match("%s*as%s+(%w+)") print(class,parent,alias) if class and parent then print(class,parent) --pcall(function() local obj=Instance.new(class) if alias then aliases[alias]=obj end objects[#objects+1]=obj --end) end end |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:19 AM |
| I would process it line by line, not in chunks between new and create. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 28 Mar 2015 12:21 AM |
Also, how do you people freaking tab on the forums?
This is tabbed but it doesn't show up!!!! >:( |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Mar 2015 12:22 AM |
that's how :) Roblox changed that a couple weeks? (or months, I don't remember) ago. |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:24 AM |
So apparently the preview is broken, but not the main site.
So nice to know... |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:27 AM |
| What's the benefit of line-by-line rather than in chunks? |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:29 AM |
| It's easier, as you only have to focus on a specific line for your string patterns. The more content you try to capture, the more complicated the patterns since Lua doesn't support the | notation in string patterns. |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:46 AM |
I'm pretty sure I have everything fixed up. It still matches in chunks, but I might change that later. The only problem I have left is that 'parent' is a string value and I'm too tired to think. How can I convert this? |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:48 AM |
| I wouldn't store it as a string name. Store it as a "Full name" (like how Instance:GetFullName() returns the entire hierarchy path to the object) and parse the path. |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:50 AM |
| parent=match:match("%s*%a+%s+in%s+(%S+)") or match:match("%s*%a+%s+in%s+(%$%-%d+)") or getAlias("%s*%a+%s+in%s+as%s+(%w+)") |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:55 AM |
@Dr Unfortunately it's not an object, it's a string. I have this: "game.StarterGui" --string and I need to get 'object' into the object value of that string. |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 12:57 AM |
| That's where parsing the path comes into play. Since you're also supporting $-n and other aliases, you'd have to consider those as well. |
|
|
| Report Abuse |
|
|