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: Help with Heartbeat/loop?

Previous Thread :: Next Thread 
EgoWitch is not online. 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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
01 Sep 2016 12:14 AM
Heartbeat is for ServerScripts
RenderStepped should be used instead
Report Abuse
EgoWitch is not online. 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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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
SadisticNub is not online. SadisticNub
Joined: 05 Jan 2013
Total Posts: 4948
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 is not online. 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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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 is not online. 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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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
SadisticNub is not online. SadisticNub
Joined: 05 Jan 2013
Total Posts: 4948
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 is not online. EgoWitch
Joined: 18 Jun 2010
Total Posts: 9555
01 Sep 2016 12:38 AM
That worked perfectly, thanks man.
Report Abuse
KreoBox is not online. 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
SadisticNub is not online. SadisticNub
Joined: 05 Jan 2013
Total Posts: 4948
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 is not online. 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
SadisticNub is not online. SadisticNub
Joined: 05 Jan 2013
Total Posts: 4948
01 Sep 2016 12:54 AM
lol
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