Jump to content

question teams


Bean666

Recommended Posts

Hi i just wanna know if i did it correctly, i created teams from a table, like this, it works fine, it creates the teams in the table, but i just wanna know if there's a better way / optimized of doing it or is this fine?

local teams = { 
  { "Team1", 0, 180, 0 }, 
  { "Team2", 180, 50, 50 } 
} 
  
for k,v in ipairs( teams ) do 
        teams = createTeam ( v[1], v[2], v[3], v[4]) 
end 

 

Edited by Shaman123
Link to comment
  • Bean666 changed the title to question teams
  • Moderators

You have the most optimized way of creating the teams.

But this code 

teams = createTeam

is wrong, as you are overriding the teams variable as you are iterating over that list.

The 1st one gets created, the second should fail because that teams variable just changed for the team entity you created in the 1st iteration of the loop.

You can also write it like this (by using unpack):

for k, v in ipairs( teams ) do 
    createTeam( unpack(v) ) -- unpack can be used here because it is in the same order
end

but it's less optimized (if this is not a time critical code, then it will just save you time writing the code, but not by much either :p)

  • Like 1
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...