This is my single catching [VAL] code:
function Lang(string,value1)
lang=gsub(string,"%b[]", value1)
return lang
end
how do I make it catch all the [] in a sentence ???
ex:
Hello [USER] your IP is [IP] and you are sharing [SHARE]
how will this be done in above code.
help me out plz.
Noob on gsub.
/NL
i have no idea what you mean but ?
data = gsub(data,"%b[USER]",value1)
data = gsub(data,"%b[IP]",value2)
data = gsub(data,"%b[SHARE]",value3)
Plop, Wombat, Tezlo, Chilla could you guys help me...
Kepp's sol. didn't work so good.
wanna get this working but don't know a thing about gsub.
plz / NL
one way , stripped from LIS
no there are many ways ;).
kepp's only need s alittle modifing to works, well it works depending on what purpose
well i think the problem is that
you have let's say a line like this
LINE = "Hello [USER], Your IP is [IP], and you are sharing [SHARE]"
value = user.sName
value1 = user.sIP
You grab the user's Share and set that to value2..
LINE = gsub(LINE,"[USER]",value)
print(LINE)
Output : Hello user.sName, Your IP is [IP], and you are sharing [SHARE]
and you do like that till you catch all of them, might be some easier way..
I've never actually dealt with gsub so much :)
or
LINE = gsub(LINE,"%[USER%]",value)
depending on the purpose ;)
or..
welcomemsg = " hey [username] ([userip]) you are sharing [usershare]b"
uservars = {
username = function(user)
return user.sName
end,
userip = function(user)
return user.sIP
end,
usershare = function(user)
local s, e, share = strfind(user.sMyInfoString, "%$(%d+)%$%|$")
return s and tonumber(share)
end,
-- and so on
}
function dolang(user, str)
str = gsub(str, "%[(%a+)%]", function(id)
local func = uservars[id]
if func then
return func(%user)
else
return id
end
end); return str
end
function NewUserConnected(user)
user:SendData(dolang(user, welcomemsg))
end
Thx tezlo, but don't get all.
The function should be for all my text its not only for "user" could be for ex. my userinfo to. how do I make this right. with my above code.
Your code looked like I could use.
Will try it when I come home from my parents.
But more about gsub guys plz. Everything is good.
more more more.... :-) plz...
/NL
Isnt it so, that gsub only can replace one value at a time?
My guess is that you had to use strfind, and then substitute each value with gsub.
Only my two cent :))
manual reads..
gsub (s, pat, repl [, n])
Returns a copy of s in which all occurrences of the pattern pat have been replaced by a replacement string specified by repl.
nl.. just make a function for it in uservars
Yepp, you are right, as usual. :)
Forgotten how powerful gsub is.
Sorry for my interference.
check crazy bot and the next example (which is a mod from a piece of crazy).
OutputString = gsub(InputString, "(%S+)", function(word) return replace(word) end)
function Replace(word)
if TableWichHoldsWhatYouWannaReplace[word] then
word = TableWichHoldsWhatYouWannaReplace[word]
end
return word
end
with this you can replace every word in a string 1 by 1.
plop
thx alot guys. understand more now..
hmm plzzzzzzzz help lol
>>> in gekko ass is replaced with another word
but if someone says pass then it changes the ass bit
how can i fix this so it only does it if its its by itself on one word
QuoteOriginally posted by (uk-kingdom)pH?tt?
hmm plzzzzzzzz help lol
>>> in gekko ass is replaced with another word
but if someone says pass then it changes the ass bit
how can i fix this so it only does it if its its by itself on one word
check the hint i gave for NL, works for U 2.
my guess it that you now use a seperate gsub for everything you want 2 replace.
by using a function u can make that into 1.
plop
QuoteOriginally posted by plop
QuoteOriginally posted by (uk-kingdom)pH?tt?
hmm plzzzzzzzz help lol
>>> in gekko ass is replaced with another word
but if someone says pass then it changes the ass bit
how can i fix this so it only does it if its its by itself on one word
check the hint i gave for NL, works for U 2.
my guess it that you now use a seperate gsub for everything you want 2 replace.
by using a function u can make that into 1.
plop
no i use a table
["word"]="whatever",
but ill hvae a look yep :)
I have realy forgotten how powerfull this language can be...
thank you tezlo for refreshing my mind :)
My solusion for my problem.
function Arg(str,val1,line1,val2,line2,val3,line3,val4,line4,val5,line5)
if line1 and val1 then str = gsub(str,"%b["..line1.."]",val1) end
if line2 and val2 then str = gsub(str,"%b["..line2.."]",val2) end
if line3 and val3 then str = gsub(str,"%b["..line3.."]",val3) end
if line4 and val4 then str = gsub(str,"%b["..line4.."]",val4) end
if line5 and val5 then str = gsub(str,"%b["..line5.."]",val5) end
return str
end
Is find this easy. Ok there is some "writings" but that it always will be.
Thx for all the help / NL