generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Table acting funny

Previous Thread :: Next Thread 
superbobman is not online. superbobman
Joined: 29 Nov 2008
Total Posts: 939
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 is not online. 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
superbobman is not online. superbobman
Joined: 29 Nov 2008
Total Posts: 939
07 May 2015 02:55 PM
And how do I get example two to work?
Report Abuse
ganger800 is not online. 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
superbobman is not online. superbobman
Joined: 29 Nov 2008
Total Posts: 939
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
superbobman is not online. superbobman
Joined: 29 Nov 2008
Total Posts: 939
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
superbobman is not online. superbobman
Joined: 29 Nov 2008
Total Posts: 939
07 May 2015 03:44 PM
Anyone?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image