1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

Variable name

Discussion in 'Development' started by Vortix, Jul 30, 2014.

  1. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Wasn't sure what else to call this to be honest.
    Say I had a table, to which:
    Code:
    Rank[0] = "i5"
    Then another to which
    Code:
    Div[0]="JUDGE"
    This continues through all the MPF ranks and divisions.
    Then, I had some variables:
    JUDGEi5mdl, which stores the path to a model, continuing til the highest rank of each division. I have quite lengthy code, it goes through each rank of each division, returning or setting their model, so I attempt to switch to tables. What I was wondering, to go about this, is if there was a way to use the Rank[0] part in a variable name. This is not 100% clear, so I'll give an example
    Code:
    return Div[z]..Rank[y].."mdl"
    Div[z] would be JUDGE, Rank[y] would be i5, therefore by putting everything together you would get:
    Code:
    return JUDGEi5mdl
    .
    It would also be good to be able to create variable names using other variables, so creating the variable JUDGEi5mdl using
    Code:
    Div[z]..[Rank[y].."mdl"
    As well as returning it's value. My main experience is in VB.NET, and I know by this means it likely isn't possible, however it is possible. Is it possible in such a way through LUA?
     
  2. As far as I know you can't create a variable like that. You can however use the names as table indexes, aka:

    local tbl = {}
    tbl[Div[z]..Rank[y].."mdl"] = "blablabla"

    which does hopefully come down to the same thing (as I assume you'll be creating lots of variables).
     
  3. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Right, good point, thanks. You would be correct in thinking I would have lots of variables.
    Despite the mass of variables being used it still takes up less space overall when I convert all my code to tables.
     
  4. Also, just to have it noted in here. I don't know how all the rest of your variables look, but you can also use two-dimensional tables (or n-dimensional ones).

    tbl = {};
    tbl[Div[z]] = {}; (or 'tbl[Div[z]] = tbl[Div[z]] or {}' as 'create if it doesn't exist yet')
    tbl[Div[z]][Rank[y]] = "blablabla" for example.
     

Previous Readers (Total: 0)