#Is it possible to use this syntax for the script to work?

24 messages · Page 1 of 1 (latest)

shy rover
#

I have about 20 ids to get the recipe from and I didn't want to have 20 lines with the same code (I'll add more in the future) I wanted to shorten the code if possible
I had the idea of ​​creating something like this (if possible) creating another loop with an array with the ids replacing the color with ${color} to be used in the other loop

I think that by the third image you can understand what I wanted to do

dawn hatchBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

hexed moth
#

the second one is good

#

the other 2 shouldn't even work, because you are trying to concatenate the variable color before its defined, and its not inside these ``

shy rover
#

I saw in almostunified they also use this in their config and I thought it was possible to do the same thing with the script I needed

rich ibex
#

you can use

eval('`' + str + '`')
shy rover
#

so str = print?

rich ibex
#

with str I'm just referring to the string, in this case your id

shy rover
#

ok i think i understand

hexed moth
#

i mean, you can do string.replace("{material}", material)

#

i would personally use the second approach tbh, looks clean to me

shy rover
#

like this?

hexed moth
#

you can remove the colors array

#

and use this in the foreach

//...
Color.DYE.forEach(color => { ...
shy rover
#

works now with this

#

i dont need to set Color.DYE this variable or kubejs give suport for that?

hexed moth
#

it has support, it is an array with all colors

#

that is equal to yours

shy rover
#

ah ok thx

shy rover
hexed moth
#

probably, idk tbh im quite new to it

shy rover
#

ah ok and thx ❤️