TomsGames
|
  |
| Joined: 11 Oct 2013 |
| Total Posts: 1615 |
|
|
| 31 Mar 2014 06:46 AM |
creators = { "carsroblox", "carsme", -- I've defined this and carsothers elsewhere "carsothers" --But for this it doesnt matter }
_G["carsroblox"] = {"ModBlueCar", "ModGreenJeep", "ModPoliceCar", "ModRedTruck", "ModSchoolBus", "ModSportsCar"}
function joe() local creator = creators[1] for i = 1, #(_G[creator]) do print(_G[creator][i]) end end
joe()
This script prints lots of nils. Why? |
|
|
| Report Abuse |
|
|
TomsGames
|
  |
| Joined: 11 Oct 2013 |
| Total Posts: 1615 |
|
| |
|
BenBonez
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 19362 |
|
|
| 31 Mar 2014 07:12 AM |
I think this is more practical:
_G["Cars"] = {}
_G["CarsOfRoblox"] = {"ModBlueCar", "ModGreenJeep", "ModPoliceCar", "ModRedTruck", "ModSchoolBus", "ModSportsCar"}
function joe() for i, car in pairs(_G["Cars"]["CarsOfRoblox"]) do print(car) end end
joe() |
|
|
| Report Abuse |
|
|
TomsGames
|
  |
| Joined: 11 Oct 2013 |
| Total Posts: 1615 |
|
|
| 31 Mar 2014 07:13 AM |
| Noo I don't think you understand, there are two variables. One picks a value from creators and that selects a table to read from, the second variable select a value from the second table. |
|
|
| Report Abuse |
|
|
BenBonez
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 19362 |
|
|
| 31 Mar 2014 07:19 AM |
That's essentially what mine does too without requiring extra variables and an extra table just for the indexes which is redundant. Here with an extra variable:
function joe() local creator = _G["Cars"]["CarsOfRoblox"] for i, car in pairs(creator) do print(car) end end |
|
|
| Report Abuse |
|
|
TomsGames
|
  |
| Joined: 11 Oct 2013 |
| Total Posts: 1615 |
|
| |
|