Jump to content

Concatenate a variable name


'LinKin

Recommended Posts

So I've these variables:

num1 acc1 top1

num2 acc2 top2

num3 acc3 top3

num4 acc4 top4

num5 acc5 top5

num6 acc6 top6

Those are GUI Labels.

In the client, I recieve a table containing info about tops, so I want to set these GUI text to the values that the table brings. But how? I tried this. But it shows an error in the debug attempt to concatenate global 'num' (a nil value)

for i = 1, #returnTable do 
        guiSetText(num..i , returnTable[i][1]) 
        guiSetText(acc..i , returnTable[i][2]) 
        guiSetText(top..i , returnTable[i][3]) 
end 

Do you understand what I'm trying to do?

- Suggestions please.

Link to comment
  • Moderators
So I've these variables:

num1 acc1 top1

num2 acc2 top2

num3 acc3 top3

num4 acc4 top4

num5 acc5 top5

num6 acc6 top6

No need to be a pro scripter to say you should use a table.

Btw to answer your question, you can use loadstring. But it needs a lot of computer/server resources (relativly with a code which would use tables):

for i = 1, #returnTable do 
    loadstring("guiSetText(num"..i..", returnTable[i][1])")() 
    loadstring("guiSetText(acc"..i..", returnTable[i][2])")() 
    loadstring("guiSetText(top"..i..", returnTable[i][3])")() 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...