undefined Posted September 15, 2014 Posted September 15, 2014 Hey guys. İ have a question. How to change string to variable? What is the this method? Thanks to all...
MIKI785 Posted September 15, 2014 Posted September 15, 2014 String to variable? What the hell? String is a type of variable. Lua Scripter Owner of mshost.cz MTA portal.
undefined Posted September 15, 2014 Author Posted September 15, 2014 I think you dont understand me. For example: Change "pers" to pers
Mr.Aleks Posted September 15, 2014 Posted September 15, 2014 pers = "pers" Some opportunities come once in a lifetime Skype: alex.migliore1
darhal Posted September 15, 2014 Posted September 15, 2014 Noway u can't do this ever there is noway #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
undefined Posted September 15, 2014 Author Posted September 15, 2014 pers = "pers" Oh, no! e.g --Client function testFunc() triggerServerEvent("testTrigger", localPlayer, "pers") end --Server local testTable = { pers = {"test1","test2"} } addEvent("testTrigger", true) addEventHandler("testTrigger", getRootElement(), function(test) outputChatBox("The table say: "..(testTable.test[#testTable.test])..".") -- I want to get testTable.pers but it's get testTable."pers" end How to change "pers" to pers...
Mr.Aleks Posted September 15, 2014 Posted September 15, 2014 Do you want to get "test" from the table and then use it inside the outputChatBox? I don't understand what you wanna get Some opportunities come once in a lifetime Skype: alex.migliore1
undefined Posted September 15, 2014 Author Posted September 15, 2014 Do you want to get "test" from the table and then use it inside the outputChatBox?I don't understand what you wanna get addEvent("testTrigger", true) addEventHandler("testTrigger", getRootElement(), function(test) end) So test arguement is string. How to remove string?
darhal Posted September 15, 2014 Posted September 15, 2014 U cant change string to variable #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
Mr.Aleks Posted September 15, 2014 Posted September 15, 2014 If test is a string, try using testTable[test] Some opportunities come once in a lifetime Skype: alex.migliore1
undefined Posted September 15, 2014 Author Posted September 15, 2014 If test is a string, try using testTable[test] But i need remove the string. U cant change string to variable So what is the loadstring?
Et-win Posted September 15, 2014 Posted September 15, 2014 ...He wants to set a STRING to a VARIABLE. So "string" Has to become string So you can use it for string = stuff But as far as I know, not possible. ~Scripts~ Clan War System V1.2.0 ~Maps~ [DM]Et-win - The Run [FUN]Et-win - Drift Rocket [FUN]Et-win - Drift Rocket // [DD]Et-win - Cross 3xC
darhal Posted September 15, 2014 Posted September 15, 2014 I understand him thats why i said thats impossible #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
AboShanab Posted September 15, 2014 Posted September 15, 2014 try it loadstring ( "return paris" ) ( ) Skype : aboshanab_
AboShanab Posted September 15, 2014 Posted September 15, 2014 I know, not possible. Skype : aboshanab_
Et-win Posted September 15, 2014 Posted September 15, 2014 And what's so funny about it? ~Scripts~ Clan War System V1.2.0 ~Maps~ [DM]Et-win - The Run [FUN]Et-win - Drift Rocket [FUN]Et-win - Drift Rocket // [DD]Et-win - Cross 3xC
undefined Posted September 15, 2014 Author Posted September 15, 2014 try it loadstring ( "return paris" ) ( ) Im try it but i cant make this. Can you give me example on the table?
arezu Posted September 15, 2014 Posted September 15, 2014 If test is a string, try using testTable[test] But i need remove the string. Like Mr.Aleks said, use testTable[test] That will give you the table which holds "test1" and "test2". testTable[test] is the same as testTable.pers if test is a string that is equal to "pers", just like testTable["pers"] is the same as testTable.pers
Moderators IIYAMA Posted September 16, 2014 Moderators Posted September 16, 2014 tables can replace every variable in your whole code if you want. myScript = { ["variableName"] = "IIYAMA", ["variableWhut"] = 345763645984366, ["thisFunction"]= function () outputChatBox("thisFunction") end, ["thatFunction"]= function () outputChatBox("thatFunction") end } outputChatBox(myScript["variableName"]) outputChatBox(myScript["variableWhut"]) myScript["thisFunction"]() myScript["thatFunction"]() as arezu said you can also use the: . outputChatBox(myScript.variableName) myScript.thisFunction() and this is how you clear them: myScript["thisFunction"] = nil myScript.thisFunction = nil I prefer the ["name"], because in my opinion it is clearer and you will have the benefit that you can put every kind of data between the [ ]. Which can make your code more dynamic. When you use the . you can only access with strings. 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
Saml1er Posted September 16, 2014 Posted September 16, 2014 try it loadstring ( "return paris" ) ( ) if you don't know about environments then it's better not to use loadstring because you can't nil the variable just like that, you need to change environment using setmetatable and you don't even need to use loadstring for this + lua.org suggests that you should use pcall. local var = loadstring ("print(1)") pcall (var)
MTA Team botder Posted September 18, 2014 MTA Team Posted September 18, 2014 If test is a string, try using testTable[test] But i need remove the string. What do you mean with remove the string? testTable[test][1] = nil testTable[test] = nil GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
Et-win Posted September 18, 2014 Posted September 18, 2014 I know, not possible. I see that you don't answer anymore. Next time if you can't even explain yourself, then be silent. ~Scripts~ Clan War System V1.2.0 ~Maps~ [DM]Et-win - The Run [FUN]Et-win - Drift Rocket [FUN]Et-win - Drift Rocket // [DD]Et-win - Cross 3xC
DakiLLa Posted September 18, 2014 Posted September 18, 2014 If I'm not wrong, you can access any variable from _G table: _G[ "my_var_name_goes_here" ]
DeVo Posted September 18, 2014 Posted September 18, 2014 You can use tables .. I wrote nothing. Nothing.
Moderators IIYAMA Posted September 19, 2014 Moderators Posted September 19, 2014 Why don't we wait for AbaZaSiRiN00 to reply. All those double posts lead to nothing. 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
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