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: Sorry to re-post but I want to be a little more clear.

Previous Thread :: Next Thread 
Keltrin is not online. Keltrin
Joined: 01 Jan 2014
Total Posts: 2085
18 May 2017 07:33 PM
local table = {
"hi", "im", "stupid", "and", "gay", "please", "send", "help"
}

for i, v in pairs(table) do
print(i)
wait(1)
print(v)
end

Okay so if I run this, instead of printing everything at the same time, it prints the index of the first table element, waits a second, then prints the value.

I'm wondering, is there ANY way to make every element evaluate the code within the loop at the same time without doing something like this:

local table = {
"hi", "im", "stupid", "and", "gay", "please", "send", "help"
}

for i, v in pairs(table) do
spawn(function()
print(i)
wait(1)
print(v)
end)
end

The reason I don't want to use this way is because the spawn causes latency.
Solutions?
Report Abuse
rockandrol120 is not online. rockandrol120
Joined: 03 Nov 2012
Total Posts: 52
18 May 2017 07:38 PM
###########################################################################
Report Abuse
rockandrol120 is not online. rockandrol120
Joined: 03 Nov 2012
Total Posts: 52
18 May 2017 07:38 PM
wiki.roblox.com/index.php?title=Global_namespace/String_manipulation


Report Abuse
Keltrin is not online. Keltrin
Joined: 01 Jan 2014
Total Posts: 2085
18 May 2017 07:44 PM
Why can you people ignore the actual specifics of the issue and focus on the general issue regarding INSTANTLY ITERATING THROUGH THE TABLE!

Ignore the printing! This scenario is an institutionalized version of the actual issue! I want a generalization or someone to explain why I can't generalize.
Report Abuse
10MilesWide is not online. 10MilesWide
Joined: 06 Aug 2014
Total Posts: 2220
18 May 2017 07:47 PM
We'll need to know exactly what you're doing
Report Abuse
Froast is not online. Froast
Joined: 12 Mar 2009
Total Posts: 3134
18 May 2017 07:48 PM
Spawn doesn't cause latency. What might slow your code down is defining a new function every iteration, try something like this:

function op(i, v)
print(i)
wait(1)
print(v)
end

for i, v in pairs(table) do
coroutine.resume(coroutine.create(op), i, v)
end
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
18 May 2017 07:49 PM
No, you can't do it instantaneously w/out usage of coroutines. If this relates to the other thread, I gave you a solution that would change the TextLabels instantaneously.

In this case, it doesn't matter how you do it though - you have to use coroutines for them all to print at the same time.


Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
18 May 2017 07:50 PM
froast to the rescue


Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
18 May 2017 07:57 PM
You don't need to use coroutines here even though they're a nice way to do it.
Task switching is relatively more expensive but in your case it doesn't matter whatsoever.

for i, v in pairs(table) do
print(i)
end
wait(1)
for i, v in pairs(table) do
print(v)
end
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
18 May 2017 07:59 PM
cntkillme to the rescue aswell


Report Abuse
Keltrin is not online. Keltrin
Joined: 01 Jan 2014
Total Posts: 2085
18 May 2017 08:34 PM
Hmm
So what would I do in a more complex scenario such as:

for _, v in pairs(game.Players:GetPlayers()) do
local int = v:FindFirstChild("IntValue")
if int then
wait(1)
int.Value = int.Value + 1
end
end

Assuming I wanted to apply your solution cntkillme?
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
18 May 2017 08:36 PM
local playerz,intz = game.Players:GetPlayers(),{};

for _, v in pairs(playerz) do
local int = v:FindFirstChild("IntValue")
if int then
intz[#intz+1] = int;
end
end

wait(1);

for _,v in next,intz do v.Value = v.Value + 1; end


Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
18 May 2017 09:18 PM
The real question is why would you do that keltrin
Report Abuse
10MilesWide is not online. 10MilesWide
Joined: 06 Aug 2014
Total Posts: 2220
19 May 2017 05:20 AM
while wait(1) do
for _, v in pairs(game.Players:GetPlayers()) do
local int = v:FindFirstChild("IntValue")
if int then
int.Value = int.Value + 1
end
end
end


wiki.roblox.com/index.php/Absolute_beginner%27s_guide_to_scripting
Report Abuse
10MilesWide is not online. 10MilesWide
Joined: 06 Aug 2014
Total Posts: 2220
19 May 2017 05:21 AM
wait(1)
for _, v in pairs(game.Players:GetPlayers()) do
local int = v:FindFirstChild("IntValue")
if int then
int.Value = int.Value + 1
end
end
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