Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Using the Stamp for text is causing severe drops in framerate (lag)
- DJTHED
- Scratcher
28 posts
Using the Stamp for text is causing severe drops in framerate (lag)
In a nutshell, I'm making a script to print out text using the “Stamp” block found in the pen tab, but upon finishing it this script, it started to severely lag my project. Not knowing what was causing the lag at the time, I diagnosed the problem and found out it was the Stamp block causing the lag (If I were to remove any other block besides the stamp block, the lag would still be present). The script itself may seem absurdly large, but the reason I have it as long as it is is so that it can render out all of the text I needed printed on the screen all in ONE frame. If I were to put a “repeat until” or “repeat #” instead, it would fill out the text one letter per frame, which isn't what I want.
Here's what the the code looks like.
**EDIT**
Thanks powercon5 for giving me a cleaner way to write this code, but unfortunately it has not improved performance at all, nor has it decreased performance. I still need help with my main question.
This goes on until it's “Length of (Text) > 60”, which is the maximum amount of letters than can fit on the screen before moving on to the next line.
This is where the stamp block lies.
What I am asking for is to either find a way to optimize this so that I can still use the Stamp block for text, or perhaps finding an alternative (I don't plan on using textures as alternatives for an entire line of text, that would become tedious and annoying to create a texture for each time I need a simple line of text.)
Here's what the the code looks like.
**EDIT**
Thanks powercon5 for giving me a cleaner way to write this code, but unfortunately it has not improved performance at all, nor has it decreased performance. I still need help with my main question.
This goes on until it's “Length of (Text) > 60”, which is the maximum amount of letters than can fit on the screen before moving on to the next line.
This is where the stamp block lies.
What I am asking for is to either find a way to optimize this so that I can still use the Stamp block for text, or perhaps finding an alternative (I don't plan on using textures as alternatives for an entire line of text, that would become tedious and annoying to create a texture for each time I need a simple line of text.)
Last edited by DJTHED (Jan. 3, 2015 03:59:21)
- powercon5
- Scratcher
1000+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
there is a much easier way to make a text engine
Witty signature.
- DJTHED
- Scratcher
28 posts
Using the Stamp for text is causing severe drops in framerate (lag)
If you know a better way, please do tell. There is a reason I made this thread after all. there is a much easier way to make a text engine
- powercon5
- Scratcher
1000+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
here http://scratch.mit.edu/projects/41525390/If you know a better way, please do tell. There is a reason I made this thread after all. there is a much easier way to make a text engine
Witty signature.
- DJTHED
- Scratcher
28 posts
Using the Stamp for text is causing severe drops in framerate (lag)
Thanks, I appreciate the help. I've personally never used inputs for custom blocks before, I've never researched about them or anything since Scratch 2.0 came out.here http://scratch.mit.edu/projects/41525390/If you know a better way, please do tell. There is a reason I made this thread after all. there is a much easier way to make a text engine
However, this unfortunately does not fix the framerate issue I am having. It's not better, neither is it worse. I would post a link to the project I'm working on, but I don't think I really want it to be public yet. I may be willing to send the .sb2 file to anyone who may be able help though.
- powercon5
- Scratcher
1000+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
cou;d you not share it let me have a look and then unshare itThanks, I appreciate the help. I've personally never used inputs for custom blocks before, I've never researched about them or anything since Scratch 2.0 came out.here http://scratch.mit.edu/projects/41525390/If you know a better way, please do tell. There is a reason I made this thread after all. there is a much easier way to make a text engine
However, this unfortunately does not fix the framerate issue I am having. It's not better, neither is it worse. I would post a link to the project I'm working on, but I don't think I really want it to be public yet. I may be willing to send the .sb2 file to anyone who may be able help though.
Witty signature.
- drmcw
- Scratcher
1000+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
powercon5 has already shown you a better way. Your 60 nested if loops are totally unnecessary and you should, as you state, use a repeat loop instead. You're correct that a repeat loop will do one loop every 1/30 second but if it is in a custom block then run the custom block without screen refresh so it will do it all in one frame. You should look at using input parameters to custom blocks as it makes the code much tidier too.
- DJTHED
- Scratcher
28 posts
Using the Stamp for text is causing severe drops in framerate (lag)
Finding a cleaner way to write the code isn't what I'm asking for though. I rewrote the code using the inputs for the custom blocks, as well as the repeat loops, and the performance was unchanged. It's still dipping below 10 fps, and when I remove the “Stamp” brick, it shoots back to a stable 30 fps. That is where my problem lies, and I need a solution to this. powercon5 has already shown you a better way. Your 60 nested if loops are totally unnecessary and you should, as you state, use a repeat loop instead. You're correct that a repeat loop will do one loop every 1/30 second but if it is in a custom block then run the custom block without screen refresh so it will do it all in one frame. You should look at using input parameters to custom blocks as it makes the code much tidier too.
Last edited by DJTHED (Jan. 1, 2015 11:47:27)
- drmcw
- Scratcher
1000+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
No but “run without screen refresh” is the answer. Stamping and costume switching can be slow but Scratch should manage 60 per frame without loss.Finding a cleaner way to write the code isn't what I'm asking for though. I rewrote the code using the inputs for the custom blocks, as well as the repeat loops, and the performance was unchanged. It's still dipping below 10 fps, and when I remove the “Stamp” brick, it shoots back to a stable 30 fps. That is where my problem lies, and I need a solution to this. powercon5 has already shown you a better way. Your 60 nested if loops are totally unnecessary and you should, as you state, use a repeat loop instead. You're correct that a repeat loop will do one loop every 1/30 second but if it is in a custom block then run the custom block without screen refresh so it will do it all in one frame. You should look at using input parameters to custom blocks as it makes the code much tidier too.
- DJTHED
- Scratcher
28 posts
Using the Stamp for text is causing severe drops in framerate (lag)
This is not the answer. I've had that box checked that and it all updates the text all in one frame. That's fine and dandy, but it still dips the framerate like it did before.No but “run without screen refresh” is the answer. Stamping and costume switching can be slow but Scratch should manage 60 per frame without loss.Finding a cleaner way to write the code isn't what I'm asking for though. I rewrote the code using the inputs for the custom blocks, as well as the repeat loops, and the performance was unchanged. It's still dipping below 10 fps, and when I remove the “Stamp” brick, it shoots back to a stable 30 fps. That is where my problem lies, and I need a solution to this. powercon5 has already shown you a better way. Your 60 nested if loops are totally unnecessary and you should, as you state, use a repeat loop instead. You're correct that a repeat loop will do one loop every 1/30 second but if it is in a custom block then run the custom block without screen refresh so it will do it all in one frame. You should look at using input parameters to custom blocks as it makes the code much tidier too.
- drmcw
- Scratcher
1000+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
Then you should share the project as there is something else going on I suspect. e.g. hidden pixel bug…are your costume sizes reasonable?This is not the answer. I've had that box checked that and it all updates the text all in one frame. That's fine and dandy, but it still dips the framerate like it did before.No but “run without screen refresh” is the answer. Stamping and costume switching can be slow but Scratch should manage 60 per frame without loss.Finding a cleaner way to write the code isn't what I'm asking for though. I rewrote the code using the inputs for the custom blocks, as well as the repeat loops, and the performance was unchanged. It's still dipping below 10 fps, and when I remove the “Stamp” brick, it shoots back to a stable 30 fps. That is where my problem lies, and I need a solution to this. powercon5 has already shown you a better way. Your 60 nested if loops are totally unnecessary and you should, as you state, use a repeat loop instead. You're correct that a repeat loop will do one loop every 1/30 second but if it is in a custom block then run the custom block without screen refresh so it will do it all in one frame. You should look at using input parameters to custom blocks as it makes the code much tidier too.
- DJTHED
- Scratcher
28 posts
Using the Stamp for text is causing severe drops in framerate (lag)
https://www.dropbox.com/s/3vdcv5hxraesdh6/9.sb2?dl=0Then you should share the project as there is something else going on I suspect. e.g. hidden pixel bug…are your costume sizes reasonable?This is not the answer. I've had that box checked that and it all updates the text all in one frame. That's fine and dandy, but it still dips the framerate like it did before.No but “run without screen refresh” is the answer. Stamping and costume switching can be slow but Scratch should manage 60 per frame without loss.Finding a cleaner way to write the code isn't what I'm asking for though. I rewrote the code using the inputs for the custom blocks, as well as the repeat loops, and the performance was unchanged. It's still dipping below 10 fps, and when I remove the “Stamp” brick, it shoots back to a stable 30 fps. That is where my problem lies, and I need a solution to this. powercon5 has already shown you a better way. Your 60 nested if loops are totally unnecessary and you should, as you state, use a repeat loop instead. You're correct that a repeat loop will do one loop every 1/30 second but if it is in a custom block then run the custom block without screen refresh so it will do it all in one frame. You should look at using input parameters to custom blocks as it makes the code much tidier too.
This is the raw file if you want to have a look. At the moment I'd rather not make it public on my profile until I feel it's in a presentable state.
Last edited by DJTHED (Jan. 1, 2015 12:27:29)
- drmcw
- Scratcher
1000+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
I get 5fps but if I remove costume switching and stamping I get 8 fps. So yes costume switching and stamping are somewhat slow but they are not the main cause of lag in your project. I haven't been through all the scripts but there does seem to be quite a bit going on and that is where the majority of the lag is happening.
- DJTHED
- Scratcher
28 posts
Using the Stamp for text is causing severe drops in framerate (lag)
Are you sure? If I remove both costume switching and stamping I go from 8 fps to 30 fps. I even get well over 60 fps when I enable turbo mode.
Here's a quick video of me showing this:
http://youtu.be/AzNkz4lLMao
Here's a quick video of me showing this:
http://youtu.be/AzNkz4lLMao
Last edited by DJTHED (Jan. 1, 2015 23:31:08)
- stickfiregames
- Scratcher
1000+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
The problem with running without screen refresh is that it can make the project hang or skip if other scripts are running at the same time. I couldn't tell if this was happening, but if it is then you might want to change it. It could also just be the large number of assets in the project, it did take a long time to load and autosave.
Yay, my 1000th post!
Yay, my 1000th post!
- LionsStair
- Scratcher
100+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
Since you have such large amount of costume switching, and like SFG said:
So the only real solution is come up with a more compact way, which may take me a while to figure out myself, or figure out the main lag producer (probably the costumes changing) or it could be your internet or computer… The problem with running without screen refresh is that it can make the project hang or skip if other scripts are running at the same time. It could also just be the large number of assets in the project, it did take a long time to load and autosave.
If I said no support highlight this from “Hi” to “AWESOME”:
Hi this isThink about your suggestion, was it going to benefit a majority of scratchers, did it have cons to a specific group, was it fully based on YOUR opinion, did you put some thought into the idea, simply forgot to read the sticky, has little pros, no purposeful reason, was there something wrong with scratch? If any of these apply to you think about your post, either revise it or close it.AWESOME
If I said support highlight this from “Hi” to “COOL”:
Hi I think this isDo you think you could add to your suggestion, or do you wish to keep it the same? Doesn't matter as long as people support it!!COOL
Because I can do stuff Highlight:If you followed my instructions, I will give you a free stuffollow
Check out my feed here! List of my favorite music
Because I can do stuff:
Like this ^ and this v
You must be hallucinating!
automagiacally = automatically do something
If you don't get the pun: *Facepalm*
KUMQUATS ARE HERE TO EAT, EAT, EAT!
Remember to ALWAYS: Clicky That Sticky!
A Lion's Stare is a neutral stare yet is filled with so many stairs of moods, it never hurts, or never loves, it never does, or never nothing. A Lion's Stare is a Stair.
Life's a mystery, yet so unfair,
DEAL WIT IT.
(Insert epic lion face here)
- DJTHED
- Scratcher
28 posts
Using the Stamp for text is causing severe drops in framerate (lag)
I don't think the abundance of data in my project is causing the lag. I decided to save a copy and remove EVERYTHING (which includes the music and textures) except for the script to print out the text, and it's still going below 15 fps.
…
Below 15 fps.
With only a line of text and some numbers.
…
At this point, I'm still certain that it's costume switching and stamping that's causing the lag. I know it's not my computer specifically causing it, I've tested this on multiple PCs in my house. They are all recent models, they don't have Intel processors from 10 years ago in them. I don't see why my internet connection would effect anything when scratch only contacts the servers when I load the project, save the project, or when I'm using cloud variables. Even then, the lag problem is still present in the offline editor.
…
Below 15 fps.
With only a line of text and some numbers.
…
At this point, I'm still certain that it's costume switching and stamping that's causing the lag. I know it's not my computer specifically causing it, I've tested this on multiple PCs in my house. They are all recent models, they don't have Intel processors from 10 years ago in them. I don't see why my internet connection would effect anything when scratch only contacts the servers when I load the project, save the project, or when I'm using cloud variables. Even then, the lag problem is still present in the offline editor.
Last edited by DJTHED (Jan. 2, 2015 00:51:26)
- AonymousGuy
- Scratcher
1000+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
I want to help diagnose this - I will make a post if I find anything, because it definitely can't be just costume switching and stamping.
EDIT 1: it is definitely not the custom block - running the custom block by itself has no lag issues.
EDIT 2: ran a little script drawing text at a bunch of different positions - no lag
EDIT 3: huh - this really does seem to be the issue, I can't understand why though
EDIT 1: it is definitely not the custom block - running the custom block by itself has no lag issues.
EDIT 2: ran a little script drawing text at a bunch of different positions - no lag
EDIT 3: huh - this really does seem to be the issue, I can't understand why though
Last edited by AonymousGuy (Jan. 2, 2015 04:00:45)
- DJTHED
- Scratcher
28 posts
Using the Stamp for text is causing severe drops in framerate (lag)
EDIT 3: huh - this really does seem to be the issue, I can't understand why though
Ah well. Perhaps it's just a Scratch 2.0 issue..? Maybe? Idk, I think I remember seeing some projects do something similar to this for text and it didn't seem to cause huge drops to the framerate… But I honestly can't say for sure.
I hope I can get this fixed soon… somehow… It just seems really silly that this is even a problem. Of all things, I didn't expect printing text onto the screen would be the most taxing thing for Scratch 2.0.
- drmcw
- Scratcher
1000+ posts
Using the Stamp for text is causing severe drops in framerate (lag)
You do seem to be hitting the limit and the primary culprit seems to be the costume switching. It looks like there is plenty you can do to optimise things, the main one being to just draw things when they change rather than updating the whole screen all the time.
- Discussion Forums
- » Help with Scripts
- » Using the Stamp for text is causing severe drops in framerate (lag)