Lag when exporting functionality into a block in Scratch - mit-scratch

I'm new to scratch.
I have this code within a sprite, which works as expected without noticeable lags:
But, when I "export" the flickering into the 'flicker' block, it has a very nasty lag:
I created a special sprite in order to easily "feel" the lag, with this code:
This ball smoothly moves, until (every 5 seconds) there is the flickering effect and it stops for 1 second or so.
Can anyone give me a clue why it happens, and how to prevent it?
The project page is here.
Any assistance would be appreciated.

Let me start by pointing out that the problem does not occur when I launch your project.
I tried it in 5 different web browsers on 3 different devices with 2 different operating systems, and every time, the ball just kept moving.
However, I can make such an issue happen by enabling 'Run without screen refresh' in the 'flicker' block, as follows:
Right-click on the red 'define flicker' block.
From the context menu, select 'Edit'.
In the 'make a block' dialog, turn on checkbox 'Run without screen refresh', then click OK.
I suspect 'Run without screen refresh' claims all processing power, effectively blocking any other (concurrent) scripts.
My guess is, you already fixed the problem yourself by turning off 'Run without screen refresh'.
In general, 'Run without screen refresh' is a great way to reduce lag in scripts where speed is essential. But never use it in a script with 'wait' or 'forever' blocks, or it will cause lag.

Related

Unity: Fps drops after a while

I am building an Unity application as a visual stimulation for a neuroscience study. Basically, my application just shows several flickering planes periodically. However, I noticed that every time after I ran the application for a few minutes, the fps dropped to around 10~30 shown in the profiler. The drop of fps happened in both editor mode or build. Since my script is totally in cycle, I am guessing there were some accumulative issues like GC or memory leak?
Also, I noticed that when the fps starts to become unstable, I can click the Pause button in the tool bar of the Editor and then resume the application, the fps will become stable for a further period. Therefore, I am wondering what actually happens when the Pause button is clicked? Does pressing the Pause button clear or reset anything so the fps can go back to full?
When I had a similar problem, it helped just turning off "Record" in the Unity profiler. Recording consumes so much memory and the fps drop, especially when there are a lot of function calls (like deep recursions).
It doesn't sound like you are constantly creating new GameObjects and not deleting the old ones, but that would be the 2nd thing that comes to mind.
If you use lot of drag-drop references or in short form [SerializeFields], you will lose performance resulting reduced FPS. Try to get everything you want in Awake, specially MonoBehaviours, this worked for me to increase FPS. By everything I didn't mean you have to keep things hard coded everywhere. Just the classes and other things like gameObjects. Floats, int, bools,strings, lists<> should be okay and better to be serialized.

Game not running after start button is pressed

There are no compile errors or warnings. My game just starts paused. I can look around but everything is frozen. I even tried to call Time.timeScale = 1; from various start functions. "Error on Pause" is turned off.
Restarting Unity has no effect.
Why is this happening?
HINT:
I figured out that calling Time.timeScale = 1; was not working because the gameObject where the script was attached to, was not set to active.
Check your Time Manager. Sometimes it gets randomly corrupted and the scale drops to Zero.
Time Manager (menu: Edit > Project Settings > Time)
Have you tried to force unpause in script?
EditorApplication.isPlaying = true;
Game can start paused also because of some unknown problems with assests so you can try to reimport them. If it doesn't help your next move should be to reinstall unity.
Also make sure you don't do some very time consuming operations on Awake() and Start().
If anyone else has this error and the described solutions have not helped, check that the Editors Pause on Error option is not checked. If you go the console window you will see that tab option highlighted at the top of the window if it is on, unticking that will allow the game to play if it is starting paused because of an error. This option being turned on would likely be your issue if the issue replicates across different projects.

PsychToolbox SSVEP

I want to make an 'SSVEP' flickering lines on the monitor using PsychToolbox.
By the way, when I made a 6Hz-flickering line, it sometimes disappeared: I guess there is some conflict between 6Hz-flickering stimulus presentation and the monitor refresh rate (60Hz).
How can I solve this problem?
If you could provide the code, it would be most appreciated.
In principle, you should wait for "vsync" (just before displaying a new 60-Hz frame), and then "flip" to the other (already filled) screen buffer.

autohotkey launch apps on specific monitors

I'm fairly new to AHK, but have already done some research on this and haven't found a good answer. I would like to be able to launch an application maximized on a specific monitor. I think the current best practice is to Run the app and then use WinMove to position.
Currently I have a three panels in the following configuration: Left (1680x1050), Middle (1920x1080), Right (1920x1080).
The logic to Run and WinMove seems straightforward, but since I have different resolutions and I would like to Run the apps maximized I'm at a loss for how to script this out.
Any suggestions?
Yeah, thats about right.
What I would do is Run, then WinMove horizontally to the correct monitor, then WinMaximize

How to Repair Microsoft Surface v2 Enter Surface Mode

We've received the new Microsoft Surface v2 this week, and I've done something such that it broken the Surface Mode.
What should happen
I could double-tap the shortcut to Enter Surface Mode, say ok to the dialogs that popped up, and it would take me to the SurfaceLoader (a program that just shows a ring of particles pulsing in an out of the center). After a moment, the water-simulation Attract program would pop-up, where I could touch the center surface logo to see the list of registered Surface programs.
What happens instead
I double-tap the shortcut to Enter Surface Mode (turning on debugging), and nothing comes up past SurfaceLoader. It seems that the other programs are running, but SurfaceLoader is aggressively maintaining focus.
What might have messed things up
Installed my Surface 1 Application
Made my Surface 1 Application run on startup
Installed Surface SDK Samples
(Maybe) accidentally moved an important file elsewhere - (just because its so easy to accidentally moving things on the Surface in Windows 7 Touch.)
Let's go over each of these.
For my Surface 1 Application, built in XNA using the Surface 1 SDK, we used an .msi installer to install the program. It ran, but being that Surface 1 is built around a small program called SurfaceInput.exe running in the background, the program did not respond to input. The program was run at startup through a registry key.
I have uninstalled the program through the control panel (double check this)
I have double-checked the registry to make sure the keys are not still there
For the Surface SDK Samples, I got them from the Microsoft Surface 2 SDK at: http://www.microsoft.com/download/en/details.aspx?id=26716. After installing the SDK, I navigated (on the Surface) to C:/Program Files (x86)/Microsoft SDKs/Surface/v2.0/Samples/Surface Code Samples.zip. I extracted the zipped files, and installed them with InstallSamples.bat. Installation succeeded normally.
At some point, I was able to see a list of these in the Surface Application Launcher screen. I can no longer get to that point, so I'm unable to exactly recreate my steps.
I'm not sure where these examples extract to - the placement does not seem to be contained in InstallSamples.bat file, and I cannot find them with Windows Search. Perhaps they are built in the same folder and merely registered elsewhere with the Surface, but since then I have done a series of System Backups. When examining the Surface Configuration Editor, BingSurface is the only Application registered with it, leading me to believe these are probably not the cause.
Finally I may have accidentally moved some arbitrary file to some other directory. This does sound rather horrible of me, and while I don't recall an instance where I've done this, it is incredibly easy to accidentally move a file or folder when Surface is in Windows 7 Touch mode. Even while writing this, I somehow moved the taskbar from the bottom of the screen to the top of the screen while it was locked with just two touches. I don't think this is the problem, but its easy enough to do that I can't rule it out either.
To remedy this, I have tried Windows System Restore. I was able to restore to a point after installing my Surface 1 app, but I have tried twice to Restore to the original state of the surface without success. I waited 10-20 minutes for System Restore to show progress, and both times it stayed on the Initializing screen. It was not graphically frozen, as the Windows loading circle was spinning, but from my previous experiences 20 minutes seemed to be way too long for this process to be going correctly.
Things that do not work
Running Enter Surface Mode w/ debugging - eternal loading screen. Can alt+tab to see Attract is running, but does not switch focus to Attract window. Can hear the sounds of Attract play when I touch the surface on the loading window.
Running Surface Shell - eternal loading screen. Can hear the sounds of attract play.
Running Enter Surface Mode w/ debugging in Single Application Mode set to SurfaceBing - eternal loading screen. Alt+tab reveals its running, but does not switch focus to bing window.
Running Surface Shell in Single Application Mode set to SurfaceBing - eternal loading screen. Alt+tab reveals its running, but does not switch focus to bing window.
Running Surface Loader - running it directly causes same problems as above.
Things that do work
Compiled Sample Project RawImageVisualizer on separate system - runs great on the surface. Can see what the pixelsense is seeing.
Launching Bing for Microsoft Windows Directly - works just as it should
Launching Attract directly from C:\Program Files (x86)\Microsoft Surface\v2.0\Attract - watery program comes up just as it should.
Environment Lighting Optimizer - works totally fine.
It seems like something happened to SurfaceLoader, such that it thinks it should always be on top of everything. I shall give System Restore another go, allowing it a full hour. I will also double-check the properties of SurfaceLoader to make sure it doesn't have anything akin to "run on top" checked.
I know Surface 2 is new, but I would greatly appreciate any tips you have.
You've probably figured it out by now, but for posterity's sake, I'm guessing you didn't have permissions set correctly. You should always run the Surface Shell/Enter Surface Mode as Administrator or set the properties to always run as admin. Your own programs always need high level permission. If you don't run as admin, it seems to raise the alert window you get when Windows7 asks for higher level permissions but you never see it. It just waits and waits. "Surface Mode" is actually just a special user that's hidden until you enter it and never runs Windows Explorer or shows the desktop. So you have to deal with Windows 7 permissions to have programs run for both users. Hope that helps!