You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
lets say we have a variable in a script:
variable1 = “mynextvar”
now I want to create a new variable. but the name of the new variable needs to be the value of variable1
in the real script the value of variable1 can change
What is the issue? Include screenshots / videos if possible!
i cant find out how to create a variable that has a name of a value of another variable
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
googleing how to create values (only beginners tutorials found)
search for it on bing
search on dev hub
creating a variable called new and then “new.Name = mynextvar”
creating a variable called new and then “new.Value.Name = mynextvar”
creating a variable called new and then “newValue.Value.Name = mynextvar”
creating a variable called new and then “newValue.Name = mynextvar”
This basically returns the “environment” of the function passed in the argument of getfenv() so that you can do things like getfenv(functionName) to return the environment of the function.
This is similar to a table of variables allowing you to set various things within the function and global environment of a script via indexing.
function printMessage()
print(message)
end
local env = getfenv(printMessage)
env.message = "Hello, function environments"
printMessage() --> Hello, function environments
No, don’t do that. If this is for a module, editing the environment of the requiring script completely defeats the purpose of modules. Also using global variables is bad practice; it makes your code messy.
Reconsider your design. Do you reallyneed this? Your explanation (I read it before you deleted it) didn’t really make much sense, so if you could re-explain it that would be appreciated
basically it is a collaboration of 3 different scripts
controller-universe-model (each of these is a script in some way)
the universe holds signals
the controller can edit signals that exist in the universe
the model can read signals from the universe and perform functions related to those signals.
(why I chose to do this is a long… long story)
at the moment I am working on the model trying to make it listen to the right signals from the universe.
for that, you need to know what is inside the universe.
the universe has signals ranging from C001 to C100 every signal can be assigned a number value
every model has a starter address (say C040) and a set number of signals to listen for (let’s say its 6 for this one so that means C040, C041…C046)
local Channel1 = game.workspace.universe.C040
Channel1.Onchanged:Connect(Function(C040)
print("whatever needs to happen")
end
local Channel2 = game.workspace.universe.C041
Channel1.Onchanged:Connect(Function(C041)
print("whatever needs to happen")
end
the issue is that the address and the amount of channels to listen to is unknown and can vary between models
I hope this helps and clear things up.
don’t mind the actual code written inside of this. as it is just an example