|
| 23 Mar 2012 09:09 PM |
Say I had a script that created string values to hold data for a game.
Score:123, Level:9, LastMap:CrossRoads
that sort of thing.
How would I be able to load the players score, level and last map in separate pieces? Say I only needed the score right now sort of thing.
|
|
|
| Report Abuse |
|
|
|
| 23 Mar 2012 09:14 PM |
Ehh string manipulation...I'm rough at this but I believe this is how (I replaced your colons with slashes as it makes it easier:
local s = [[Score/123/, Level/9/, LastMap/CrossRoads/]] local t = {}
for value in s:gmathc("(/%w+/)") do table.insert(t, value) end
print("Score:"..t[1].." Level:"..t[2].." LastMap:"..t[3]) |
|
|
| Report Abuse |
|
|
|
| 23 Mar 2012 11:26 PM |
So what exactly is going on there in the for part?
|
|
|
| Report Abuse |
|
|
|
| 23 Mar 2012 11:27 PM |
| Or more specifically 's:gmathc("(/%w+/)")' |
|
|
| Report Abuse |
|
|
| |
|
|
| 24 Mar 2012 09:05 AM |
thats over complicating things..
x="Score:123, Level:9, LastMap:CrossRoads"
so you say this is your string ? colon,_=x:find(":") comma,__=x:find(",") score=x:sub(colon+1,comma-1)
so you got your scrore.. and for level and lasmap you could use the same way tell me if you need help with it. |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2012 10:29 AM |
| I think I get it. Thanks for the help. |
|
|
| Report Abuse |
|
|
Athism
|
  |
| Joined: 05 Jun 2008 |
| Total Posts: 68 |
|
|
| 24 Mar 2012 10:35 AM |
@DragonFang,
Mine was actually simpler because you don't have to continuously look for each value individually. |
|
|
| Report Abuse |
|
|