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 » Scripting Helpers
Home Search
 

Re: Pathetic with tables - please help iteration?

Previous Thread :: Next Thread 
Navydev is not online. Navydev
Joined: 21 Feb 2012
Total Posts: 274
26 Sep 2013 05:19 PM
So, I know the basics of them, and going through objects in general, but for the life of me I don't understand why my table stops printing halfway through. The script:

Actors = {"Tyler","Darian","Iggy","Cameron","Bailey","Dominick","Kat","Steve","Daniel"}
c = 0
print("---------------------------------------------------------------------------------------------------------------------------------------------------")
for _, p in pairs(Actors) do
wait(.25)
r = math.random(1,#Actors)
if c == 0 then
print("Bottom is worked by: "..Actors[r])
table.remove(Actors,r)
elseif c == 1 then
print("Second is worked by: "..Actors[r])
table.remove(Actors,r)
elseif c == 2 then
print("Third is worked by: "..Actors[r])
table.remove(Actors,r)
elseif c == 3 then
print("and worked by: "..Actors[r])
table.remove(Actors,r)
elseif c == 4 then
print("Top is worked by: "..Actors[r])
table.remove(Actors,r)
elseif c == 5 then
print("Bridge is worked by: "..Actors[r])
table.remove(Actors,r)
elseif c == 6 then
print("Infirm is worked by: "..Actors[r])
table.remove(Actors,r)
elseif c >= 7 then
print("Preliminary people assigned, here are the last remaining "..(#Actors).." people: "..returning())
end
c = c + 1
end

function returning()
local cc = 0
for _, pp in pairs(Actors) do
cc = cc + 1
print(Actors[cc])
end end


--------------

The Output:
---------------------------------------------------------------------------------------------------------------------------------------------------
Bottom is worked by: Iggy
Second is worked by: Tyler
Third is worked by: Bailey
and worked by: Cameron
Top is worked by: Daniel




What do I do?
Any suggestions or details to make this cleaner? I know for a fact that the constant "if" statements are a mess, there has to be a way to make that neater...
Report Abuse
Navydev is not online. Navydev
Joined: 21 Feb 2012
Total Posts: 274
26 Sep 2013 05:35 PM
Bump?
Report Abuse
Salinas23 is not online. Salinas23
Joined: 28 Dec 2008
Total Posts: 37142
26 Sep 2013 06:06 PM
Expect an answer not soon...

I have a spider on my back.
Report Abuse
Navydev is not online. Navydev
Joined: 21 Feb 2012
Total Posts: 274
26 Sep 2013 06:22 PM
Owtch, hope it doesnt bite you
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
26 Sep 2013 06:31 PM
function returning()
local cc = 0
for _, pp in pairs(Actors) do
cc = cc + 1
print(Actors[cc])
end end

Change this to

function returning()
for cc, pp in ipairs(Actors) do
print(pp)
end end

Ipairs is what your looking for.

The l0z3r p00p3r of ATR
Report Abuse
Geomaster is not online. Geomaster
Joined: 05 Jul 2008
Total Posts: 1480
26 Sep 2013 06:38 PM
Use another table to clean up those bulky 'Ifs'


Actors = {"Tyler","Darian","Iggy","Cameron","Bailey","Dominick","Kat","Steve","Daniel"}
Stages = {"Bottom", "Second", "Third", "Top", "Bridge", "Infirm"}
local c = 1
print("---------------------------------------------------------------------------------------------------------------------------------------------------")
for _, p in pairs(Actors) do
wait(.25)
r = math.random(1,#Actors)
if c <= #Stages then
print(Stages[c] .." is worked by: " ..p
table.remove(Actors[r])
elseif c > #Stages then
print("Preliminary people assigned, here are the last remaining "..(#Actors).." people: "..returning())
end
c = c + 1
end
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
26 Sep 2013 06:39 PM
Anyways, instead of using C, use Ipairs.

The l0z3r p00p3r of ATR
Report Abuse
Navydev is not online. Navydev
Joined: 21 Feb 2012
Total Posts: 274
26 Sep 2013 06:54 PM
How does Ipairs replace using a counter?
Report Abuse
Navydev is not online. Navydev
Joined: 21 Feb 2012
Total Posts: 274
26 Sep 2013 07:00 PM
Right, with some tweaks, the script is now:

Actors = {"Tyler","Darian","Iggy","Cameron","Bailey","Dominick","Kat","Steve","Daniel"}
Stages = {"Bottom", "Second", "Third", "Third2", "Top", "Bridge", "Infirm"}
local c = 1
print("---------------------------------------------------------------------------------------------------------------------------------------------------")
for _, p in pairs(Actors) do
wait(.25)
r = math.random(1,#Actors)
if c <=(#Stages) then
print(Stages[c].." is worked by: "..p)
table.remove(Actors,r)
elseif c> (#Stages) then
print("Preliminary people assigned, here are the last remaining "..(#Actors).." people: "..returning())
end
c = c + 1
end

function returning()
for cc, pp in ipairs(Actors) do
print(Actors[pp])
end end

...However, it still stops counting at five, when it should instead iterate the amount of spots, before stopping at the remainder of people.

It still stops at 5 - what do?

.-.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Sep 2013 07:02 PM
print(pp)

or

print(Actors[cc])
Report Abuse
Navydev is not online. Navydev
Joined: 21 Feb 2012
Total Posts: 274
26 Sep 2013 09:42 PM
The mystery shall never be solved
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Sep 2013 09:44 PM
I already solved it...
Report Abuse
Navydev is not online. Navydev
Joined: 21 Feb 2012
Total Posts: 274
27 Sep 2013 01:03 PM
You didn't solve the original purpose of the script - in that It always stops halfway through. Even with this newer version of it, the problem is still the same, and so it is unsolved.

:S
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
27 Sep 2013 07:56 PM
for c,v in ipairs(table) do

c is the counter. It's built in with Ipairs

The l0z3r p00p3r of ATR
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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