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 |
|
|
|
| 18 May 2017 07:38 PM |
| ########################################################################### |
|
|
| Report Abuse |
|
|
|
| 18 May 2017 07:38 PM |
wiki.roblox.com/index.php?title=Global_namespace/String_manipulation
|
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 18 May 2017 07:47 PM |
| We'll need to know exactly what you're doing |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
| |
|
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
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 18 May 2017 07:59 PM |
cntkillme to the rescue aswell
|
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|