Jump to content

"str" to str


JeViCo

Recommended Posts

Posted (edited)

Hello everyone! How can i transform a string to variable? For example i have "text" string and i want to make text variable. Is That possible? I need it for guiRadioButtonGetSelected

I know that i can make it with third variable but code become longer then\\

Edited by Juuve
Posted
41 minutes ago, Juuve said:

Hello everyone! How can i transform a string to variable? For example i have "text" string and i want to make text variable. Is That possible? I need it for guiRadioButtonGetSelected

I know that i can make it with third variable but code become longer then\\

i think that you can't convert a string to variable 

Chillin' with some demons, satans and vamps

  • MTA Team
Posted (edited)

Well technically you could do:

_G["mystring"] = theValueYouWantToAssignIt

After that the variable mystring becomes available just as any regular variable.

Edited by Megadreams
  • Thanks 1
  • Moderators
Posted

Or you can use loadstring.

local value = true
loadstring("text = " .. tostring(value))()

https://www.lua.org/pil/8.html

 

@Megadreams hmm interesting, I didn't know that you could also make global variables like that.

  • Thanks 2

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...