Hello, I tried using keyof<> and typeof() functions in my code but it doesn’t work and I don’t understand the error message.
Here is my code:
function unicodeProgressBar.generateBar(value: number, minRangeValue: number, maxRangeValue: number, length: number, background_block: keyof<typeof(CONSTANTS.BACKGROUND_BLOCKS)>): string
local bar: string = ""
local normalizedValue: number = (value - minRangeValue) / (maxRangeValue - minRangeValue)
local scaledToLengthValue: number = length * normalizedValue
local scaledToLengthValueWhole: number, scaledToLengthValueMantissa: number = math.modf(scaledToLengthValue)
local quantizedScaledValueMantissa: number = quantize(scaledToLengthValueMantissa, CONSTANTS.INTERVAL)
for _ = 1, scaledToLengthValueWhole, 1 do
bar ..= CONSTANTS.BLOCKS[8]
end
bar ..= CONSTANTS.BLOCKS[quantizedScaledValueMantissa * CONSTANTS.INTERVAL_DENOMINATOR]
for _ = 1, length - scaledToLengthValueWhole, 1 do
--
bar ..= CONSTANTS.BACKGROUND_BLOCKS[background_block] -- HERE IS THE ERROR
--
end
return bar
end
Here is the CONSTANTS module:
local CONSTANTS = {}
CONSTANTS.BLOCKS = {[0] = "" --[[ Necessary as indices start at 1 ]], "▏","▎","▍","▌","▋","▊","▉","█"} -- to self: smooth right to left bars are not possible as the necessary characters do not exist in unicode
CONSTANTS.BACKGROUND_BLOCKS = {
["NONE"] = "",
["TRANSPARENT"] = " ",
["MINIMAL"] = "░",
["MEDIUM"] = "▒",
["MEDIUM_REVERSED"] = "�",
["FULL"] = "▓"
}
CONSTANTS.INTERVAL = 1/8
CONSTANTS.INTERVAL_DENOMINATOR = 8
return CONSTANTS
I put my CONSTANTS in a separate script as to avoid cyclic requires.
Pls help.
Cannot add indexer to table means you’re trying to index a table with an invalid data type. I don’t know where you are getting keyof<> from but as far as i’m aware that is not a valid operator in Lua?
local CONSTANTS = {}
CONSTANTS.BLOCKS = {[0] = "" --[[ Necessary as indices start at 1 ]], "▏","▎","▍","▌","▋","▊","▉","█"} -- to self: smooth right to left bars are not possible as the necessary characters do not exist in unicode
CONSTANTS.BACKGROUND_BLOCKS = {
["NONE"] = "",
["TRANSPARENT"] = " ",
["MINIMAL"] = "░",
["MEDIUM"] = "▒",
["MEDIUM_REVERSED"] = "�",
["FULL"] = "▓"
}
CONSTANTS.INTERVAL = 1/8
CONSTANTS.INTERVAL_DENOMINATOR = 8
function generateBar(value: number, minRangeValue: number, maxRangeValue: number, length: number, background_block: keyof<typeof(CONSTANTS.BACKGROUND_BLOCKS)>): string
local bar: string = ""
local normalizedValue: number = (value - minRangeValue) / (maxRangeValue - minRangeValue)
local scaledToLengthValue: number = length * normalizedValue
local scaledToLengthValueWhole: number, scaledToLengthValueMantissa: number = math.modf(scaledToLengthValue)
local quantizedScaledValueMantissa: number = 1 -- Replaced cuz i dont have the quantize function
for _ = 1, scaledToLengthValueWhole, 1 do
bar ..= CONSTANTS.BLOCKS[8]
end
bar ..= CONSTANTS.BLOCKS[quantizedScaledValueMantissa * CONSTANTS.INTERVAL_DENOMINATOR]
for _ = 1, length - scaledToLengthValueWhole, 1 do
--
bar ..= CONSTANTS.BACKGROUND_BLOCKS[background_block] -- HERE IS THE ERROR
--
end
return bar
end
print(generateBar(1, 0, 100, 10, "FULL"))
No such error as what you are getting is appearing for me. I did leave away the quantize function but I doubt that has any effect.
Thank you. I’ll poke around and see what I can find. My hunch is that it’s a quirk with the fact you’re using a module script to store the unicode data but I’m not sure yet
I’ve done a bunch of digging and this pending bug seems to be your case: Release Notes for 647 | Documentation - Roblox Creator Hub.
"Fixes new solver crashes related to unions of tables. Users might see false positive errors related to “Cannot add indexer to table”. "