EgoWitch
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 9555 |
|
|
| 01 Sep 2016 12:13 AM |
Trying to get this image to change from Anim[1] to Anim[25] one by one through the array by using RunService but I'm having no luck :l. Also wanting it to go back to Anim[1] when it reaches Anim[25] :l
Thanks for any help, I am new to scripting.
---
local RunService = game:GetService('RunService')
--LOADINGANIM 1-25 local Anim = {} -- array going from 1 to 25, removed for thread spam sake
Id = "http://www.roblox.com/asset/?id=" Load = script.Parent.IntroGui.Content.LoadingAnim -- imagelabel
wait(5)
RunService.Heartbeat:connect(function(step) for i = 1, #Anim do local newID = Id..Anim[i] Load.Image = newID if i == 25 then i = 1 else print("Time between each loop: "..step) end end end)
---
Thanks again for any help. |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 12:14 AM |
Heartbeat is for ServerScripts RenderStepped should be used instead |
|
|
| Report Abuse |
|
|
EgoWitch
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 9555 |
|
|
| 01 Sep 2016 12:19 AM |
| Just tried RenderStepped and it still didn't work, the image isn't changing :/ |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 12:21 AM |
"for i = 1, #Anim do local newID = Id..Anim[i] Load.Image = newID if i == 25 then i = 1 else print("Time between each loop: "..step) end end"
Why are you going through all of the animations? Especially in RenderStepped
that means that every 1/60th of a second, the image is going to be reset and the function will be called again, running after any already called functions |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 12:21 AM |
"Heartbeat is for ServerScripts RenderStepped should be used instead"
you're dumb they both work locally, except heartbeat also works server-sided. they both run at the framerate.
heartbeat is generally better to use. |
|
|
| Report Abuse |
|
|
EgoWitch
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 9555 |
|
|
| 01 Sep 2016 12:26 AM |
Why are you going through all of the animations? Especially in RenderStepped
because you said to use renderstepped
and because i want it to change every 1/60 |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 12:28 AM |
Still, you are making it go through all the images with 1) no waiting at all 2) every 1/60 of the frames
if you want to see it change:
for i = 1, #Anim do local newID = Id..Anim[i] Load.Image = newID wait() end |
|
|
| Report Abuse |
|
|
EgoWitch
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 9555 |
|
|
| 01 Sep 2016 12:30 AM |
| 1/60 of a second is waiting and I should be able to see it because the human eye can actually see faster than 1/30 of a second, believe it or not. |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 12:32 AM |
well like I said before, the entire loop will run every time a new frame appears
which means you probably wont event see any changes because the only frame you would see is after you run that entire loop |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 12:34 AM |
OP, try this:
local step = 1/30 -- duration between image changes
while true do for i = 1, #Anim do Load.Image = Id..Anim[i] wait(step)
if i >= #Anim then break end end end |
|
|
| Report Abuse |
|
|
EgoWitch
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 9555 |
|
|
| 01 Sep 2016 12:38 AM |
| That worked perfectly, thanks man. |
|
|
| Report Abuse |
|
|
KreoBox
|
  |
| Joined: 24 Aug 2016 |
| Total Posts: 356 |
|
|
| 01 Sep 2016 12:40 AM |
local RunService = game:GetService('RunService')
--LOADINGANIM 1-25 local Anim = {} -- array going from 1 to 25, removed for thread spam sake
local Id = "rbxassetid://" local Load = script.Parent.IntroGui.Content.LoadingAnim -- imagelabel local Step = 1
wait(5)
RunService.RenderStepped:connect(function() Load.Image = Id .. Anim[Step] Step = Step + 1 if Step == 26 then Step = 1 end end) |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2016 12:41 AM |
| Or you could, you know, use a numeric for loop instead of making your own index variable. |
|
|
| Report Abuse |
|
|
drahsid5
|
  |
| Joined: 13 May 2011 |
| Total Posts: 3937 |
|
|
| 01 Sep 2016 12:48 AM |
Please, never use Heartbeat:connect() use while heartbeat:wait() do, it's much more efficient. Secondly, when you iterate through the array, and yield while in a heartbeat loop, said heartbeat loop will also yield. Therefore you would want to iterate outside of the heartbeat loop's scope. |
|
|
| Report Abuse |
|
|
| |
|