VortDyn Posted May 30, 2022 Share Posted May 30, 2022 (edited) Can I create a variable in the variable name? Timer{playerName} = setTimer ( function(), 1000, 0 ) If the player has the nickname "Palm", then the variable "TimerPalm" should be created If the player has the nickname "Nick", then the variable "TimerNick" should be created Edited May 30, 2022 by VortDyn Link to comment
Moderators Citizen Posted May 30, 2022 Moderators Share Posted May 30, 2022 Hello @VortDyn, I moved your topic to the Scripting section. The Tutorials section is only for Scripting Tutorials, for scripting questions, use the Scripting section instead. Make sure to use this section for your next scripting questions. 1 Link to comment
DiSaMe Posted May 30, 2022 Share Posted May 30, 2022 The global environment (the table holding the global variables) can be accessed using variable _G. local playerName = getPlayerName( player ) local variableName = "Timer"+playerName _G[ variableName ] = setTimer ( function() end, 1000, 0 ) However, building variable names is usually not recommended for generic manipulation of data. Instead of putting the timers into global variable space, you can create your own table specifically for timers: -- at the top of the script playerTimers = {} -- then, somewhere in the code local playerName = getPlayerName( player ) playerTimers[ playerName ] = setTimer ( function() end, 1000, 0 ) But I suspect that's still not exactly what you want to do. Should the timer be linked to player's name, or to the player? If it's linked to the player's name, then if the player changes their name during the game, playerTimes[playerName] will no longer refer to the timer created before the change. If that's not what you want, you can bypass the retrieval of the name and just use the player element directly as table key: -- at the top of the script playerTimers = {} -- then, somewhere in the code playerTimers[ player ] = setTimer ( function() end, 1000, 0 ) 1 1 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