Tetris game
I tried to write a little game: Tetris. (I had the idea nearly at the same time like Invalid User, so this is not a copy of his version).
The script and bitmaps can be downloaded here:
http://niwi.ni.funpic.de/tetris.html
But there a still bugs and it is not really fast. Maybe someone has ideas to improve the speed so the game will be playable :-)
NiWi.
It looks great.The script and bitmaps can be downloaded here:
http://niwi.ni.funpic.de/tetris.html
Can you give more detail about which aspects of the game you want to speed up? Maybe just the startup/initialization phase?ideas to improve the speed so the game will be playable
One part which is very slow is removing a whole line because this also causes to "move" the whole upper part of the line one line down. At the moment I check if a line could be removed and move down the other bricks. After this I check the next line. I will change this and check from bottom to top if a line cann be removed, count the number of removed lines and move the upper part x lines down. This should speed up a little bit. But checking and moving is still slow.Can you give more detail about which aspects of the game you want to speed up? Maybe just the startup/initialization phase?
An other problem is checking if a key is pressed. I use the hotkeys which I disable if a subroutine is called and enable at the end of an subroutine. This is necessary because the subroutines need some time to be processed and in this case it should not be possible to have an other subroutine called. Also the timer will be dis- and enabled while the program runs a subroutine.
Chris, is it possible to have an directive so the hotkeys will be disabled while a hotkey subroutine is processed and enabled after the return?
NiWi.
The only thing I noticed: upon downloading the script and attempting to execute it, I received the following error:
Error: Parameter #3 must be a number in this case.
Specifically: v_speed
Line #
292: Transform,v_speed,Floor,v_speed
The program will exit.
After placing a ; in front of lines 291-294, the program worked fine, just didn't display the score.
Great job!
You could try reducing MaxThreads to 1 or 2:is it possible to have an directive so the hotkeys will be disabled while a hotkey subroutine is processed and enabled after the return?
#MaxThreads 1
The above would prevent your timer(s) from running except when the script is completely idle.
You could also use Suspend to disable all or some hotkeys temporarily, and re-enable them later:
Suspend On
...
Suspend Off
Finally, if you watch the CPU utilization during the removal of a complete row at the bottom and the CPU isn't maxed, that probably means there is a delay script somewhere, perhaps SetWinDelay or SetControlDelay (depending on the commands you're using).
@RG:
the line 292 is wrong, it should be
Transform,v_speed,Floor,%v_speed%
@Chris:
The CPU is at nearly 100% :-(
But the idea with #MaxThreads is good. I still use the suspend on and off method, but maybe there is a little chance that a user starts another thread if the process runs between the label and the suspend command. I'm not sure, but if anyone know this, it should be you :-)
Label: Suspend, On ...But the maxthreads shall deny this.
NiWi.
There could be a bottleneck somewhere. For example, referring to a dynamic variable such as Array%i% is a fairly slow process. In such cases, resolve Array%i% only once if it is needed multiple times:The CPU is at nearly 100% :-(
temp := Array%i%
x := temp
y := temp
Also, expressions are usually a little slower than traditional single-step math:
var := x / 3 + 100
Might be slower than:
var = %x%
var /= 3
var += 100
The really important thing to discover, however, is where the script is spending most of its time: often there are just one or two lines that are the problem, and sometimes there is a way to optimize them or do their work in a different way.
I think it should be okay without suspend if you're using "#MaxThreads 1". You might also want to look up #MaxThreadsBuffer, which determines whether hotkey presses get deferred until later if the user presses one during a forbidden time (too many threads).I still use the suspend on and off method, but maybe there is a little chance that a user starts another thread if the process runs between the label and the suspend command.
I just copied the text from an other topic:
Ok, I'll check this.It's definitely faster. I don't get any long pauses anymore and it is very playable (my game skills are improving).
As a minor issue, when the game beat me, the script gave a syntax error because the use of a negative array index is illegal (since dashes are illegal in variable names):Thanks for making this great version of Tetris!Error: This variable or function name contains an illegal character. The current thread will exit.
Specifically: v_Field[1][-1]
---> 741: __field := v_Field[%__xpos%][%__ypos%]
By the way, I've not yet tried the other Tetris script, but perhaps yours or the other one should go into the script showcase since it's a great demonstration of how to use arrays and GUI controls in creative ways (not to mention being fun).
NiWi.
is it possible to have an directive so the hotkeys will be disabled while a hotkey subroutine is processed and enabled after the return?
Thread, Setting, P2 [, P3]
"By default, every newly launched thread is uninterruptible for a Duration of 15 milliseconds or a LineCount of 1000 script lines, whichever comes first... If a hotkey is pressed or a custom menu item is selected while the current thread is uninterruptible, that event will be buffered. In other words, it will launch when the current thread finishes or becomes interruptible, whichever comes first. The exception to this is when the current thread becomes interruptible before it finishes, and it is of higher priority than the buffered event; in this case the buffered event is unbuffered and discarded."
Threads > Thread Priority > "The default priority is 0."
Solution: Set the desired subroutine to a higher priority than zero, and make sure its runtime is at least 15 ms (perhaps use Sleep 15 in the subroutine)..... This is the way to go. The only problem is, on this system anyway (Win2000 5.00.2195 SP4), i've tried the Thread command, and nonzero thread-Priority comparisons don't seem to be enabled. A fix would seem to be in order.
note: 1) during a timer's interruption, all timer commands will be acknowledged and buffered, then executed on resuming, 2) Thread: "...a thread will become interruptible the moment it displays a MsgBox, InputBox, FileSelectFile, or FileSelectFolder dialog."
2) Intuitive. Logical. Versatile. Adaptable. <
This is a fairly complex area so it would help if you could post a short script to reproduce this problem, or just describe the nature of such a script.I've tried the Thread command, and nonzero thread-Priority comparisons don't seem to be enabled. A fix would seem to be in order.