Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Custom Blocks causing lag
- yaboiyusuf321
-
Scratcher
31 posts
Custom Blocks causing lag
Hello, I have a problem with custom blocks. I am making a ray-caster and am trying to make a ray-cast script. However, when I make a custom block to do a loop, it lags. There are no wait blocks or anything, just a repeat until loop and a repeat block. It is run without screen refresh. let me show you a picture.
.
It shows:
.It shows:
define raycast create
point in direction ([direction v] of [player v])
turn ccw (60) degrees
delete (all v) of [list v]
set [distance v] to (0)
repeat (120)
go to [player v]
turn cw (1) degrees
create clone of [myself v]
when I receive [raycast v]
clear
raycast create
define moveSo those are the scripts, nothing holding it up, run without screen refresh and it still lags badly. If you want, I'll give you a link here. Thanks in advance!
repeat until <touching [level v]?>
move (1) steps
change [distance v] by (1)
when I start as a clone
move
add (distance) to [distances in view v]
stamp
delete this clone
Last edited by yaboiyusuf321 (Nov. 22, 2020 02:07:59)
- xXx-VIBIN-CAT-xXx
-
Scratcher
17 posts
Custom Blocks causing lag
when I receive [i see this v]
set [my brain v] to [blown up]
- deck26
-
Scratcher
1000+ posts
Custom Blocks causing lag
So you need to share the project, not scripts out of context.
- yaboiyusuf321
-
Scratcher
31 posts
Custom Blocks causing lag
So you need to share the project, not scripts out of context.It is shared, it's at the bottom of my post
- yaboiyusuf321
-
Scratcher
31 posts
Custom Blocks causing lag
Oh and also everyone it's in the “raycast” sprite
- Ji1mmyB
-
Scratcher
100+ posts
Custom Blocks causing lag
I am not entirely sure how the funtions(custom blocks) work on scratch. In some cases when you put a repeat it will not lag, but in most cases when you put a repeat loop the script will lag. Here is a possible solution.
You need to make sure that the Clone Direction Variable is “For This Sprite Only”. I believe that should work.
define raycast create
point towards [player]
turn ccw (60) degrees
delete (all) of [distances in view]
set [distance] to [0]
set [CloneDirection] to [0]
repeat (120)
change [CloneDirection] by (1)
create clone of [myself]
end
when I start as a clone
go to [player]
turn cw (CloneDirection) degrees
Move
add (distances) to [distances in view
stamp]
delete this clone
You need to make sure that the Clone Direction Variable is “For This Sprite Only”. I believe that should work.
- yaboiyusuf321
-
Scratcher
31 posts
Custom Blocks causing lag
I am not entirely sure how the funtions(custom blocks) work on scratch. In some cases when you put a repeat it will not lag, but in most cases when you put a repeat loop the script will lag. Here is a possible solution.Thanks!define raycast create
point towards [player]
turn ccw (60) degrees
delete (all) of [distances in view]
set [distance] to [0]
set [CloneDirection] to [0]
repeat (120)
change [CloneDirection] by (1)
create clone of [myself]
endwhen I start as a clone
go to [player]
turn cw (CloneDirection) degrees
Move
add (distances) to [distances in view
stamp]
delete this clone
You need to make sure that the Clone Direction Variable is “For This Sprite Only”. I believe that should work.
- yaboiyusuf321
-
Scratcher
31 posts
Custom Blocks causing lag
I am not entirely sure how the funtions(custom blocks) work on scratch. In some cases when you put a repeat it will not lag, but in most cases when you put a repeat loop the script will lag. Here is a possible solution.It didn't seem to work but thanks anyways for making my code simpler!define raycast create
point towards [player]
turn ccw (60) degrees
delete (all) of [distances in view]
set [distance] to [0]
set [CloneDirection] to [0]
repeat (120)
change [CloneDirection] by (1)
create clone of [myself]
endwhen I start as a clone
go to [player]
turn cw (CloneDirection) degrees
Move
add (distances) to [distances in view
stamp]
delete this clone
You need to make sure that the Clone Direction Variable is “For This Sprite Only”. I believe that should work.
- ninjaMAR
-
Scratcher
1000+ posts
Custom Blocks causing lag
Use less angles. In the repeat 120 make it repeat 60 then turn 2 degrees
- Scratch-Minion
-
Scratcher
1000+ posts
Custom Blocks causing lag
Edit your “raycast create” custom block to “run without screen refresh” to create all the clones at once and all the lag will disappear.
- yaboiyusuf321
-
Scratcher
31 posts
Custom Blocks causing lag
Edit your “ray-cast create” custom block to “run without screen refresh” to create all the clones at once and all the lag will disappear.Hey @Scratch-Minion! I turned “run without screen refresh” off for testing and have turned it back on, yet it still causes lag. The problem for me is that the “run without screen refresh” is causing lag in the first place and it can't be the clones because even without them it still lags. Thanks for the help tho!
- Discussion Forums
- » Help with Scripts
-
» Custom Blocks causing lag