|
| 07 May 2015 02:49 PM |
I have 2 tables that I tried working with, example #1 is
_G.Territorys= { ["Afghanistan"] = true,{team = "", AmountOfTroops = 1, continent = "Asia"}, ["Alaska"] = true, {team = "", AmountOfTroops = 1, continent = "NorthAmerica"}, ["Alberta"] = true, {team = "", AmountOfTroops = 1, continent = "NorthAmerica"}, }
example #2 is
_G.Territorys= { ["Afghanistan"] = {true,team = "", AmountOfTroops = 1, continent = "Asia"}, ["Alaska"] = {true, team = "", AmountOfTroops = 1, continent = "NorthAmerica"}, ["Alberta"] = {true, team = "", AmountOfTroops = 1, continent = "NorthAmerica"}, }
im mutating the tables by this function
_G.CheckIfAllClaimed=function() for i,v in pairs(_G.Territorys) do if i==v then return true end if v == true then return false end end return true end
Why does example one work and not example 2, and how to do i get example 2 to work?
|
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 07 May 2015 02:52 PM |
1. I don't think you understand how table pairs work.
"["Afghanistan"] = true,{team = "", AmountOfTroops = 1, continent = "Asia"}"
That is 2 completely separate values.
2. Don't use _G.
I script -~ chimmihc |
|
|
| Report Abuse |
|
|
|
| 07 May 2015 02:55 PM |
| And how do I get example two to work? |
|
|
| Report Abuse |
|
|
ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 07 May 2015 03:00 PM |
why do you check if the index is the same as the value? (i ==v)?
second: if v[1] == true v[1] is where you store it with the example #2 and is the way you should use
third: you could also just do { Afghanistan = {true, team == "", etc}, -- etc } |
|
|
| Report Abuse |
|
|
|
| 07 May 2015 03:22 PM |
I tried your way, im getting this error Error, country has already been selected.
_G.CheckIfAllClaimed=function() for i,v in pairs(_G.Territorys) do if i==v[1] then return true end if v[1] == true then return false end end return true end while true do local check = _G.CheckIfAllClaimed() if check==true then print("All claimed") _G.AllTerritorysClaimed = true break end check = nil wait(2) end |
|
|
| Report Abuse |
|
|
|
| 07 May 2015 03:23 PM |
if _G.Territorys[territoryName] ~= true then--#2--check if territory is taken print("Error, country has already been selected.")--err |
|
|
| Report Abuse |
|
|
| |
|