TorNix~|nR Posted January 24, 2021 Posted January 24, 2021 (edited) Hello guys, I wanted to ask if I can set this languages in buttons if (getElementData(localPlayer, "Language") == "English") if (getElementData(localPlayer, "Language") == "Spanish") this is the button guiCreateButton(0, 0, 0, 0, "Police", false, panel) I'm wondering how to change the button from English to Spanish, any ideas please? I mean changing that "Police" to "Policía" (Spanish Language). Edited January 24, 2021 by TorNix~|nR ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003
Moderators IIYAMA Posted January 24, 2021 Moderators Posted January 24, 2021 (edited) 27 minutes ago, TorNix~|nR said: I'm wondering how to change the button from English to Spanish, any ideas please? You could try this, not tested. But it is a start. local languageSwitch = {} local defaultLanguage = "nl" function guiSetLangaugeSupport (element, languages) languageSwitch[#languageSwitch + 1] = {element = element, languages = languages} guiSetText(element, languages[defaultLanguage] or guiGetText(element)) return element end function guiSetLanguageSwitch (language) for i=1, #languageSwitch do local switchData = languageSwitch[i] guiSetText(switchData.element, switchData[language] or switchData[defaultLanguage] or select(2, next(switchData)) or guiGetText(switchData.element)) end end switchData[language] or -- The option you want switchData[defaultLanguage] or -- default language select(2, next(switchData)) or -- First possible item guiGetText(switchData.element) -- previous text ;O local button = guiSetLangaugeSupport(guiCreateButton(0, 0, 0, 0, "", false, panel), {en = "Police", nl = "Politie"}) Edited January 24, 2021 by IIYAMA 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
TorNix~|nR Posted January 24, 2021 Author Posted January 24, 2021 Thank you so much, I just tested it, the defaultLanguage is working fine but I want to know how to get the language I have Like I told you I am using this if (getElementData(localPlayer, "Language") == "English") if (getElementData(localPlayer, "Language") == "Spanish") I made this when the player join, he select the language (English or Spanish) if you understand what I mean 1 ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003
TorNix~|nR Posted January 24, 2021 Author Posted January 24, 2021 (edited) I'm sorry if it's confusing, I mean For example {en = "Police", es = "Policía"}) I want the "es" to get (getElementData(localPlayer, "Language") == "Spanish") and the "en" to get (getElementData(localPlayer, "Language") == "English") Edited January 24, 2021 by TorNix~|nR ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003
Moderators IIYAMA Posted January 24, 2021 Moderators Posted January 24, 2021 (edited) 7 minutes ago, TorNix~|nR said: I'm sorry if it's confusing, I mean {Spanish = "policía", English = "Police"} You could swap es with Spanish, does that help? guiSetLanguageSwitch (getElementData(localPlayer, "Language")) -- call the function local defaultLanguage = "Spanish" Edited January 24, 2021 by IIYAMA Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
TorNix~|nR Posted January 24, 2021 Author Posted January 24, 2021 local languageSwitch = {} local defaultLanguage = "English" function guiSetLangaugeSupport (element, languages) languageSwitch[#languageSwitch + 1] = {element = element, languages = languages} guiSetText(element, languages[defaultLanguage] or guiGetText(element)) return element end function guiSetLanguageSwitch (language) for i=1, #languageSwitch do local switchData = languageSwitch[i] guiSetText(switchData.element, switchData[language] or switchData[defaultLanguage] or select(2, next(switchData)) or guiGetText(switchData.element)) end end guiSetLanguageSwitch (getElementData(localPlayer, "Language")) local button = guiSetLangaugeSupport(guiCreateRadioButton(17, 27, 205, 21, "Police", false, panel), {Spanish = "policía", English = "Police"}) @IIYAMA I'm sorry but I'm a complete failure ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003
Moderators IIYAMA Posted January 24, 2021 Moderators Posted January 24, 2021 12 minutes ago, TorNix~|nR said: guiSetLanguageSwitch (getElementData(localPlayer, "Language")) It is the moment of switching languages. It should at least be executed after creating the button. Now it is executed before that. Try to run this line with a command handler or with onClientResourceStart. (that is if you know if the value is set before that) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
TorNix~|nR Posted January 24, 2021 Author Posted January 24, 2021 (edited) I used this local languageSwitch = {} local defaultLanguage = "English" function guiSetLangaugeSupport (element, languages) languageSwitch[#languageSwitch + 1] = {element = element, languages = languages} guiSetText(element, languages[defaultLanguage] or guiGetText(element)) return element end function guiSetLanguageSwitch (language) for i=1, #languageSwitch do local switchData = languageSwitch[i] guiSetText(switchData.element, switchData[language] or switchData[defaultLanguage] or select(2, next(switchData)) or guiGetText(switchData.element)) -------THE PROBLEM end end local button = guiSetLangaugeSupport(guiCreateRadioButton(17, 27, 205, 21, "Police", false, panel), {Spanish = "policía", English = "Police"}) addEventHandler( "onClientResourceStart", getRootElement( ), function () guiSetLanguageSwitch (getElementData(localPlayer, "Language")) end ); but I got this problem Bad argument @'guiSetText' [Expected string at argument 2, got table] Edited January 25, 2021 by TorNix~|nR ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003
Moderators IIYAMA Posted January 25, 2021 Moderators Posted January 25, 2021 (edited) 9 hours ago, TorNix~|nR said: Bad argument @'guiSetText' [Expected string at argument 2, got table] You need to index one more time with .languages, before you index with the actually language you want. 1. So: switchData.languages[language] 2. Same goes for the other lines that make use of that table. switchData.langauges[defaultLanguage] select(2, next(switchData.languages)) Edited January 25, 2021 by IIYAMA Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
TorNix~|nR Posted January 25, 2021 Author Posted January 25, 2021 I used this local languageSwitch = {} local defaultLanguage = "Spanish" function guiSetLangaugeSupport (element, languages) languageSwitch[#languageSwitch + 1] = {element = element, languages = languages} guiSetText(element, languages[defaultLanguage] or guiGetText(element)) return element end function guiSetLanguageSwitch (language) for i=1, #languageSwitch do local switchData = languageSwitch[i] guiSetText(switchData.languages[language] or switchData.langauges[defaultLanguage] or select(2, next(switchData.languages)) or guiGetText(switchData.element)) -----------HEREAGAIN end end local button = guiSetLangaugeSupport(guiCreateRadioButton(17, 27, 205, 21, "Police", false, panel), {Spanish = "policía", English = "Police"}) addEventHandler( "onClientResourceStart", getRootElement(), function () guiSetLanguageSwitch (getElementData(localPlayer, "Language")) end ); and got the problem in the same line guiSetText [Expected gui-element at argument 1, got string 'Police'] ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003
Moderators IIYAMA Posted January 25, 2021 Moderators Posted January 25, 2021 Provide the gui element. switchData.element And then you are ready to go Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
TorNix~|nR Posted January 25, 2021 Author Posted January 25, 2021 (edited) I'm sorry again but I didn't understand how I changed every element to button, I tried panel too but it's the same problem Edited January 25, 2021 by TorNix~|nR ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003
Moderators IIYAMA Posted January 25, 2021 Moderators Posted January 25, 2021 (edited) 29 minutes ago, TorNix~|nR said: I'm sorry again but I didn't understand how I changed every element to button, I tried panel too but it's the same problem Before (without element): guiSetText(switchData.languages[language] or switchData.langauges[defaultLanguage] or select(2, next(switchData.languages)) or guiGetText(switchData.element)) After (with element): guiSetText(switchData.element, switchData.languages[language] or switchData.langauges[defaultLanguage] or select(2, next(switchData.languages)) or guiGetText(switchData.element)) Also please stop putting confusing reactions on most of my replies, it marks them as confusing in general while most of them are not. Sure, I do not mind, if my reply does not make sense at all. You could using emotions in your own replies instead, that makes more sense. @TorNix~|nR Edited January 25, 2021 by IIYAMA 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
TorNix~|nR Posted January 25, 2021 Author Posted January 25, 2021 (edited) Sorry, I didn't know about the reply reactions It's working perfectly fine, I can't thank you enough Edited January 25, 2021 by TorNix~|nR 1 ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003
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