| View previous topic :: View next topic |
| Author |
Message |
niwi
Joined: 27 Feb 2005 Posts: 139 Location: Heidelberg, Germany
|
Posted: Thu Mar 17, 2005 9:03 pm Post subject: Tetris game |
|
|
Hi,
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. |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Thu Mar 17, 2005 10:02 pm Post subject: |
|
|
Amazing!  _________________
 |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2952 Location: Minnesota
|
Posted: Thu Mar 17, 2005 10:34 pm Post subject: |
|
|
| The speed is fine, but you're right about the bugs. I'm amazed at how nice it is already, though! I can only imagine how long this must have taken. All in all, it's a great proof of concept. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Fri Mar 18, 2005 1:36 am Post subject: Re: Tetris game |
|
|
It looks great.
| Quote: | | ideas to improve the speed so the game will be playable | Can you give more detail about which aspects of the game you want to speed up? Maybe just the startup/initialization phase? |
|
| Back to top |
|
 |
niwi
Joined: 27 Feb 2005 Posts: 139 Location: Heidelberg, Germany
|
Posted: Fri Mar 18, 2005 7:11 am Post subject: Re: Tetris game |
|
|
Hi,
| Chris wrote: | | Can you give more detail about which aspects of the game you want to speed up? Maybe just the startup/initialization phase? |
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.
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. |
|
| Back to top |
|
 |
RG
Joined: 09 Feb 2005 Posts: 17 Location: United States
|
Posted: Fri Mar 18, 2005 12:43 pm Post subject: Tetris game |
|
|
This is really nice!
The only thing I noticed: upon downloading the script and attempting to execute it, I received the following error:
| Quote: | 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! _________________ RG |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Fri Mar 18, 2005 1:02 pm Post subject: Re: Tetris game |
|
|
| niwi wrote: | | is it possible to have an directive so the hotkeys will be disabled while a hotkey subroutine is processed and enabled after the return? | You could try reducing MaxThreads to 1 or 2:
#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). |
|
| Back to top |
|
 |
niwi
Joined: 27 Feb 2005 Posts: 139 Location: Heidelberg, Germany
|
Posted: Fri Mar 18, 2005 2:56 pm Post subject: |
|
|
Hi,
@RG:
the line 292 is wrong, it should be
| Code: | | 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
| Code: | Label:
Suspend, On
...
|
But the maxthreads shall deny this.
NiWi. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Sat Mar 19, 2005 2:54 am Post subject: |
|
|
| niwi wrote: | The CPU is at nearly 100%  | 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:
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.
| Quote: | | 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 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). |
|
| Back to top |
|
 |
niwi
Joined: 27 Feb 2005 Posts: 139 Location: Heidelberg, Germany
|
Posted: Wed Apr 27, 2005 4:38 pm Post subject: |
|
|
Hi,
I just copied the text from an other topic:
| Chris wrote: | 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):
| Quote: | 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%] | Thanks for making this great version of Tetris!
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). |
Ok, I'll check this.
NiWi. |
|
| Back to top |
|
 |
Decarlo110
Joined: 15 Dec 2004 Posts: 303 Location: United States
|
Posted: Wed Apr 27, 2005 8:39 pm Post subject: |
|
|
| niwi wrote: | | 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." _________________ 1) The Open Source Definition http://www.opensource.org/docs/definition_plain.php
2) Intuitive. Logical. Versatile. Adaptable. <<AutoHotkey>> |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Thu Apr 28, 2005 12:39 pm Post subject: |
|
|
| Decarlo110 wrote: | | 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. | 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. |
|
| Back to top |
|
 |
|