miniwindow tetris

Posted by Fiendish on Thu 16 Jun 2011 06:29 PM — 16 posts, 51,063 views.

USA Global Moderator #0
After a chat with Nick the other night, I threw this together based on an old test room prog I made for Aardwolf a long time ago. It's tetris in a miniwindow. I think the only thing it's really missing is a box showing the next piece, but I kind of like the suspense of not knowing.

https://aardwolfclientpackage.googlecode.com/svn/trunk/experimental/miniwindow_Tetris.xml
Amended on Thu 16 Jun 2011 06:30 PM by Fiendish
Australia Forum Administrator #1
Very nice Fiendish! It doesn't work if you don't have any accelerators. Change OnPluginInstall to read:


function OnPluginInstall()
   -- set up temporary key accelerators
   acc_list = AcceleratorList() or {}

Australia Forum Administrator #2
This needs reworking:


function OnPluginClose()
   -- reset all temporary accelerators
   AcceleratorTo("Ctrl+Left", leftAcc or "", sendto.script)
   AcceleratorTo("Ctrl+Right", rightAcc or "", sendto.script)
   AcceleratorTo("Ctrl+Up", upAcc or "", sendto.script)
   AcceleratorTo("Ctrl+Down", downAcc or "", sendto.script)
end


Check out AcceleratorList description.

You need to grab the send-to location from inside square brackets at the end of the line, and use that to decide where to send to when putting the old accelerator back.

eg. This is what you get:



tprint (AcceleratorList ())


Gives:


1="Ctrl+Left = CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'left')     [12]"
2="Ctrl+Up = CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'rotate')     [12]"
3="Ctrl+Right = CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'right')   [12]"
4="Ctrl+Down = CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'drop')     [12]"


The keys are not the accelerator keys even, they are numeric.
Amended on Fri 17 Jun 2011 12:21 AM by Nick Gammon
Australia Forum Administrator #3
Example of extracting accelerator keys:


accels = AcceleratorList ()

if accels then
  
  for _, v in ipairs (accels) do

    local keystroke, what, where = string.match (v, "^(%S+) = (.*)%[(%d-)%]$")
    if where then
       where = tonumber (where)
    else
       keystroke, what = string.match (v, "^(%S+) = (.*)$")
       where = sendto.execute
    end -- if

    print ("keystroke =", keystroke)
    print ("what =", what)
    print ("where =", where)

  end -- for

end -- if



Gives:


keystroke = Ctrl+Left
what = CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'left')     
where = 12
keystroke = Ctrl+Up
what = CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'rotate')   
where = 12
keystroke = Ctrl+Right
what = CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'right')    
where = 12
keystroke = Ctrl+Down
what = CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'drop')     
where = 12
keystroke = Ctrl+B
what = foo
where = 10
keystroke = Ctrl+D
what = CallPlugin ('04d9e64f835452b045b427a7', 'CopyScript', '')        
where = 12

Amended on Fri 17 Jun 2011 04:53 AM by Nick Gammon
Australia Forum Administrator #4
Game looks like this:

USA Global Moderator #5
Nick Gammon said:

Very nice Fiendish! It doesn't work if you don't have any accelerators. Change OnPluginInstall to read:

function OnPluginInstall()
   -- set up temporary key accelerators
   acc_list = AcceleratorList() or {}

Thanks, but why is this? I figured it would already return an empty list (i.e {}) instead of nil or otherwise. What is "IsEmpty"?

Quote:
You need to grab the send-to location
Ack! This is what happens when I make assumptions!
USA Global Moderator #6
Nick Gammon said:

Game looks like this:


Really, Nick? 0 points? :)
USA Global Moderator #7
Nick Gammon said:
The keys are not the accelerator keys even, they are numeric.


Hmm. That's awkward. Can it be changed? Nevermind, I'll just use your example. I think it should be added to the acceleratorlist docs.
Australia Forum Administrator #8
Fiendish said:

Thanks, but why is this? I figured it would already return an empty list (i.e {}) instead of nil or otherwise. What is "IsEmpty"?


It's a VBscript variant value that indicates that the variant is empty. Translated into Lua, that means nil (no variable).

It's a bit of a throwback to the way the glue routines were implemented to take values from the COM objects (themselves generally returning Variants) and turning them into Lua values.

Quote:

Really, Nick? 0 points? :)


I said the game was good, not my playing. ;)

But OK, here is another attempt:



BTW the game needs a "pause" action. If someone pages you, or you get into a fight, you don't want to lose your Tetris game because you can't pause it. (The tall stack was when Lasher was chatting with me).

Oh, and I like the use of coroutines, makes it look nice and clean. Although I await the graphical blocks.

[EDIT] And the music. And the background image. ;P
Amended on Fri 17 Jun 2011 04:50 AM by Nick Gammon
Australia Forum Administrator #9
Fiendish said:

Hmm. That's awkward. Can it be changed? Nevermind, I'll just use your example. I think it should be added to the acceleratorlist docs.


It has been.
USA Global Moderator #10
Quote:
And the music. And the background image. ;P

I'll record a wav of me singing "Doo, doo-doo-doo, doo-doo-doo, doo-doo-doo, doo-doo-doo...do-doo, doo, doo doo dooooooo. Doooooo do doooo do do doooooo do doooo doo doo dooo do do-dooo do doo dooo dooo." :D
Australia Forum Administrator #11
Here is an improved accelerator-list extractor:


local accels = AcceleratorList ()
local taccels = {}

if accels then
  
  for _, v in ipairs (accels) do

    local keystroke, what, where = string.match (v, "^(%S+) = (.*)%[(%d-)%]$")
    if where then
       where = tonumber (where)
    else
       keystroke, what = string.match (v, "^(%S+) = (.*)$")
       where = sendto.execute
    end -- if

    taccels [keystroke] = { send = what, where = where }

  end -- for

end -- if

tprint (taccels)


Output:


"Ctrl+B":
  "send"="foo"
  "where"=10
"Ctrl+D":
  "send"="CallPlugin ('04d9e64f835452b045b427a7', 'CopyScript', '')     "
  "where"=12
"Ctrl+Down":
  "send"="CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'drop')  "
  "where"=12
"Ctrl+Left":
  "send"="CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'left')  "
  "where"=12
"Ctrl+Up":
  "send"="CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'rotate')        "
  "where"=12
"Ctrl+Right":
  "send"="CallPlugin('db6e9ed958c05658b5d7d5ea', 'do_command', 'right') "
  "where"=12

USA Global Moderator #12
I think accelerator remembering should be fixed now.
USA Global Moderator #13
And now, if you put the following file (or another of the same name) in the same directory as the plugin it will play music. :}

https://aardwolfclientpackage.googlecode.com/svn/trunk/experimental/Tetris_theme.wav
Australia Forum Administrator #14

wget http://aardwolfclientpackage.googlecode.com/svn/trunk/experimental/Tetris_theme.wav

HTTP request sent, awaiting response... 502 Bad Gateway
2011-06-17 19:23:30 ERROR 502: Bad Gateway.

Australia Forum Administrator #15
I got it working! But you need a "mute" option before I punch the screen! ;)