holuzs Posted April 17, 2019 Share Posted April 17, 2019 ENG: So, I try to make a word replacer script, but when I want to replace 2 or more word in a sentence didn't work. Someone can help me in this? HUN: Szóval, megpróbáltam csinálni egy "szó helyettesítő scriptet", de ha 2 vagy több szót akarok helyettesíteni, nem működik. Valaki tudna segíteni? An example/Egy példa: outputChatBox(exports["resourcename"]:replaceWords("%PLAYERNAME% has %PLAYERMONEY% dollar!", "%PLAYERNAME%", getPlayerName(player), "%PLAYERMONEY%", getPlayerMoney(player)) Link to comment
Moderators Patrick Posted April 17, 2019 Moderators Share Posted April 17, 2019 (edited) [HUN ]Szia! Nem tudom hogy miért így akarod cserélni a szavakat, de itt van egy megoldás a te példádra. (én nem használnám, felesleges export, függvényhívás, loop) Ebben az esetben a funkció elvárja, hogy a következőképpen kapja meg az argumenteket: replaceWords(EREDETI_SZOVEG, MIT_CSERELJEN, MIRE_CSERELJE, ..., MIT_CSERELJEN, MIRE_CSERELJE, és így tovább...) function replaceWords(text, ...) local args = {...} for i=1, #args do if (i%2 == 1) then text = text:gsub(args[i], args[i+1]) end end return text end print(replaceWords("#PLAYERNAME has #PLAYERMONEY dollar!", "#PLAYERNAME", "Patrick", "#PLAYERMONEY", 100)) (A % jeleket hanyagolnod kell, mivel az egy helyettesítő karakter. Cseréltem őket #-re.) Edited April 17, 2019 by stPatrick 1 Link to comment
holuzs Posted April 17, 2019 Author Share Posted April 17, 2019 (edited) Nyelv rendszert csinálok és ahhoz kell. Edited April 17, 2019 by holuzs Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now