Search code examples
for-loopcommand-line-interfacegarrys-mod

Garry's mod Expression 2 for loop


In a game called Garry's mod there an add on called wiremod. Inside wiremod there is expression 2 which is a conmand line basiced coding so execute commands. The command For loop I'm having issues with because I can't do variable inside a variable. In CMD I could setlocal EnableLocalExtension and do !Var%Var%! The code simpler is: (cap sensitive)

@inputs [GoCard1,GoCart2,GoCart3,GoCart4]:entity
X = 64
Y = 24

-N is the variable
-10 is max number
-1 is how much it increments by
for(N,10,1)
{
Menu:egpText(1,toString(GoCart1),vec2(X,Y)
Y+=24 -increase by 24
I++   -increase by 1
}

My problem is I can't change GoCart1 to GoCart2, GoCart3... Ect Tried GoCartN but gives me an error GoCartN does not exists Anyone have any ideas?


Solution

  • Short answer I'm going to separate the code

    @inputs [GoCard1,GoCart2,GoCart3,GoCart4]:entity
    X = 64
    Y = 24
    T = table(GoCart1,GoCart2,GoCart3,GoCart4)
    for(N,10,1)
    {
    Menu:egpText(1,"1. "+toString(T[N,entity]),vec2(X,Y)
    Y+=24 -increase by 24
    I++   -increase by 1
    }
    

    If anyone know how to put GoCart in the loop please let me know