<
title>MappyWin32 Lua scripting documentation<
/title>
<
body bgcolor="#cccccc" text="#000000" link="#0000ff" vlink="#0000aa">
<
p><
a name="topod"><
/a><
/p>
<
h2>MappyWin32 Lua scripting documentation<
/h2>
<
strong>Lua scripts<
/strong>. Added in 1.3.22, you can write
scripts to perform functions in the editor such as exporting/importing
graphics, maps and other data from custom formats, editing the map or
blocks, performing a custom task and
many other things. The scripts are written in a language called LUA
(see www.lua.org), see the copyright notice in the luascr folder.
Lua scripts can either be put in the luascr folder, and then set
the LUA values in the mapwin.ini file to add them to the Custom menu.
Alternatively, you can drag and drop a file ending with '.lua'
onto MappyWin32 to run it.<
br><
br>
I'd like to thank Robbob (Autofringe, Random distribution) and
Jerzy Kut (Export binary file) for their help with lua.
I have included some example scripts in the luascr folder (not all
of these are listed in the custom menu), look
at them in a text editor to see how they work, I am a novice with
Lua, so they are quite basic.
Load a test map and run them to see what they do, most of them
give a brief summary of what they do before they start.
You do not need to restart Mappy if you modify a script. You can
override the functions in the file menu with lua scripts to fully
customize loading and saving of maps (see mapwin.ini).
MappyWin32 extends LUA with these functions (don't forget
to prefix functions and values with 'mappy.' see the .lua files in
the luascr folder
):<
br><
br>
R
= getValue
(VALUE_ID
)<
br>
where VALUE_ID is one of:<
br>
MAPWIDTH,
MAPHEIGHT,
BLOCKDEPTH,
BLOCKWIDTH,
BLOCKHEIGHT,
NUMBLOCKSTR,
NUMBLOCKGFX,
BLOCKGAPX,
BLOCKGAPY,
BLOCKSTAGGERX,
BLOCKSTAGGERY,
CLICKMASK,
TRANS8,
TRANSRED,
TRANSGREEN,
TRANSBLUE,
CURLAYER,
CURBLOCK,
CURANIM,
CURBRUSH,
MOUSEBLOCKX,
MOUSEBLOCKY,
GETBLOCKMODE,
PALETTEARGB+index,
NUMBLOCKANIM,
XMAPOFFSET,
YMAPOFFSET,
MAPFILENAME,
MAPWINPATH,
MAPTYPE,
MAPWINVERSION,
NUMBRUSHES,
NUMLAYERS,
CUROBJECT,
NUMOBJECTS,
CMDLINE,
NUMCHUNKS,
CURGFX,
setValue
(VALUE_ID, SETVALUE
)<
br>
where VALUE_ID is one of:<
br>
TRANS8,
TRANSRED,
TRANSGREEN,
TRANSBLUE,
PALETTEARGB+index,
GETBLOCKMODE,
CURLAYER,
CURBLOCK,
CURANIM,
CURBRUSH,
XMAPOFFSET,
YMAPOFFSET,
MAPFILENAME,
CUROBJECT,
MAPTYPE,
CURGFX,
R
= shiftVal
(VALUE, SHIFT
) negative shift is left, positive is right<
br>
R
= andVal
(VALUE1, VALUE2
)<
br>
R
= orVal
(VALUE1, VALUE2
)<
br><
br>
R
= getBlock
(X, Y
[,L
])<
br>
where X is the x coord in blocks,
and Y is y coord in blocks, L is the optional layer number, omit it
for current layer<
br><
br>
setBlock
(X, Y, B
[,L
])<
br>
where X is the x coord in blocks, and Y is y coord in blocks, and B is the block index,
L is the optional layer number, omit it
for current layer
(see
'Solid rectangle.lua' for an example
)<
br><
br>
R
= getBlockValue
(B, VALUE_ID
)<
br>
where B is the block index, and VALUE_ID is one of:<
br>
BLKBG,
BLKFG1,
BLKFG2,
BLKFG3,
BLKUSER1,
BLKUSER2,
BLKUSER3,
BLKUSER4,
BLKUSER5,
BLKUSER6,
BLKUSER7,
BLKFLAG1,
BLKFLAG2,
BLKFLAG3,
BLKFLAG4,
BLKFLAG5,
BLKFLAG6,
BLKFLAG7,
setBlockValue
(B, VALUE_ID,
VALUE)<
br>
where B is the block index, and VALUE_ID is one of:<
br>
BLKBG,
BLKFG1,
BLKFG2,
BLKFG3,
BLKUSER1,
BLKUSER2,
BLKUSER3,
BLKUSER4,
BLKUSER5,
BLKUSER6,
BLKUSER7,
BLKFLAG1,
BLKFLAG2,
BLKFLAG3,
BLKFLAG4,
BLKFLAG5,
BLKFLAG6,
BLKFLAG7,
and
VALUE is the
value to write
(flags are
0 or
1) see
'Tile graphic test.lua'<
br><
br>
where B is the block index to insert the new block at<
br><
br>
where B is the block index to remove<
br>
R
= getBlockSort
(index
)<
br>
Gets the block number from the sortlist<
br>
setBlockSort
(index, B
)<
br>
If sortblocks=1 in mapwin.ini, the script luascr/BlockSort.lua is called when the
Blocks in the Block Editor window are refreshed. You can filter blocks however
you want, and put the blocks you want to display in the list<
br>
copyLayer
(SOURCE, DEST
)<
br>
where SOURCE is the layer to copy from (0 to 7 or MPY_UNDO), and DEST is the
layer to copy to
(0 to
7 or MPY_UNDO
) if you are changing the current layer, use:<
br>
mappy.copyLayer
(mappy.getValue
(mappy.CURLAYER
),mappy.MPY_UNDO
)<
br>
where G is the graphic index to insert the new graphic at<
br><
br>
where G is the graphic index to remove<
br><
br>
In the following A is Alpha, R is Red, G is Green, B is Blue, all values between
0 (none
) and
255 (max
),
0 Alpha is transparent,
255 is solid.<
br>
A,R,G,B
= getPixel
(X, Y, G
)<
br>
where X, Y is pixel coord within the graphic, G is the graphic index<
br><
br>
setPixel
(X, Y, G, A, R, G, B
) or<
br>
setPixel
(X, Y, G, INDEX
)<
br>
where INDEX is the palette index
0 to
255)<
br><
br>
R
= importGraphics
("FILENAME", GFXPOS, AMOUNT
)<
br>
where GFXPOS is the graphic number to start importing at, and AMOUNT
is the number of tiles to import. AMOUNT can be
0 for all.<
br><
br>
R
= msgBox
("TITLE",
"MESSAGE",
TYPE, ICON
)<
br>
where
TYPE is one of:<
br>
MMB_OK,
MMB_OKCANCEL,
MMB_ICONNONE,
MMB_ICONINFO,
MMB_ICONQUESTION,
MMB_CANCEL,
MMB_YES,
R,
"FILENAME" = fileRequester
("PATH",
"DESCRIPTION",
"EXTENSION",
TYPE)<
br>
where PATH is the starting folder (try "."), DESCRIPTION is what
appears in the 'Save as type' box, EXTENSION is a properly formatted mask
for file extensions (ie: "*.FMP" or "*.FMP;*.MAP"). And TYPE is either
returns R, either MMB_OK or MMB_CANCEL, also
"FILENAME"<
br><
br>
R
= doDialogue
("TITLE",
"MESSAGE",
"STRING",
TYPE)<
br>
TITLE should contain 14 or fewer characters. where TYPE is either MMB_DIALOGUE1 or MMB_DIALOGUE2, type 1 returns
MMB_OK or MMB_CANCEL and one string, type 2 returns MMB_OK or MMB_CANCEL
and as many strings as there were commas plus 1 (ie: hello,1,2,3 would
return four strings
"hello" "1" "2" and
"3")<
br>
R
= doDialogue
("DLGPROC")<
br>
"DLGPROC" is the name of the handler for dialogue messages.
See the scripts
'Dialogue Example.lua' and 'Dialogue Proc.lua'. Some knowledge of Win32
dialogues is required.<
br>
createDialogue
("Title",
STYLE, X, Y, W, H, NUMCONTROLS
)<
br>
creates a custom dialogue, STYLE can be 0 for default. See the scripts
'Dialogue Example.lua' and 'Dialogue Proc.lua'. Some knowledge of Win32
dialogues is required.<
br>
addDialogueItem
("Title",
STYLE, X, Y, W, H, IDC,
TYPE)<
br>
See defines in
'Dialogue Example.lua'<
br>
hwnd, msg, wParam, lParam
= getDialogueParam
()<
br>
See 'Dialogue Proc.lua', note: Proc is sent idc == 99 on creation so
lists can be populated and labels changed etc<
br>
checkDlgButton
(IDC, STATUS
)<
br>
Sets button IDC to STATUS<
br>
R
= isDlgButtonChecked
(IDC
)<
br>
R is STATUS of button IDC<
br>
R
= getDlgItemText
(IDC
)<
br>
R is
text of item as a string<
br>
setDlgItemText
(IDC,
"TEXT")<
br>
TEXT is new
text of item as a string<
br>
R
= sendDlgItemMessage
(IDC, MSG, WPARAM, LPARAM
)<
br>
Get and Set information for all types of buttons etc. Allows
setting and retrieving see
any tutorial on Win32 dialogues and DlgItemMessage<
br>
R
= getAnimFrame
(animnum, framenum
)<
br>
'framenum' can be ANMREFFRAME<
br>
setAnimFrame
(animnum, framenum, blockval
)<
br>
'framenum' can be ANMREFFRAME<
br>
R
= numAnimFrames
(animnum
)<
br>
insertAnimFrame
(animnum, framenum, blockval
)<
br>
cutAnimFrame
(animnum, framenum
)<
br>
R
= numAnimFrames
(animnum
)<
br>
R
= getAnimValue
(VAL
)<
br>
ANMDELAY, ANMCOUNT, ANMTYPE, ANMUSER, ANMCURFRAME<
br>
setAnimValue
(VAL, val
)<
br>
ANMDELAY, ANMCOUNT, ANMTYPE, ANMUSER, ANMCURFRAME<
br>
createBrush
(brshnum, x, y, w, h
)<
br>
deleteBrush
(brshnum
)<
br>
renameBrush
(brshnum,
"Brushname")<
br>
R
= getBrushBlock
(brshnum, x, y
)<
br>
setBrushBlock
(brshnum, x, y, blk
)<
br>
R
= getBrushValue
(VAL
)<
br>
BRUSHWIDTH, BRUSHHEIGHT, BRUSHNAME<
br>
getTextString
(index
)<
br>
setTextString
(index,
"Text")<
br>
newMap
(mapwidth, mapheight, mapdepth, tilewidth, tileheight,
[tilegapx, tilegapy, tilestaggerx, tilestaggery, maptype
])<
br>
openFMP
(["FILENAME"])<
br>
saveFMP
(["FILENAME"])<
br>
if no "filename" supplied, current filename is used. On saving,
use mappy.setValue
(mappy.MAPFILENAME,
"filename") if you want to change the name<
br>
resizeMap
(WIDTH,
HEIGHT, CENTERING
)<
br>
CENTERING is from
1 to
9 as in the MapTools:Resize dialogue<
br>
call this to refresh the display after altering a layer<
br><
br>
shellExecute
(action, file, params,
dir,
style)<
br>
call an external programme, example:
mappy.shellExecute
("open",
"notepad",
"mapwin.ini",
"c:/mapwin148/",
0)<
br>
sendMessage
(code,
0)<
br>
code is one of the key shortcuts listed in mapwin.htm<
br>
for example sendMessage
(119,
0) shows the helpfile<
br>
renameMenuItem
(code,
"Name")<
br>
code is one of the key shortcuts listed in mapwin.htm.
"Name" is the new
name for the menu item<
br>
moveWindow
(WINDOW, x, y,
width,
height)<
br>
added
(WINDOW
= MPY_MAINWINDOW, MPY_MAPWINDOW or MPY_BLOCKWINDOW
)<
br>
createObject
(position
)<
br>
deleteObject
(objnum
)<
br>
R
= getObjectValue
(objnum, VALUE_ID
)<
br>
setObjectValue
(objnum, VALUE_ID, objval
)<
br>
VALUE_ID for the above can be one of:
OBJXPOS,
OBJYPOS,
OBJGFXID,
OBJTILEID,
OBJGXOFF,
OBJGYOFF,
OBJGWIDTH,
OBJGHEIGHT,
OBJGHANDLEXOFF,
OBJGHANDLEYOFF,
OBJSHOW,
OBJUSER1,
OBJUSER2,
OBJUSER3,
OBJUSER4,
OBJUSER5,
OBJUSER6,
OBJUSER7,
R
= getObjectFilename
(index
)<
br>
Gets the string for the image filename displayed in the Object Properties dialogue,
'index' is the position in the list<
br>
setObjectFilename
(index,
"Filename")<
br>
Sets the string for the image filename displayed in the Object Properties dialogue,
'index' is the position in the list<
br>
R
= getObjectSort
(index
)<
br>
Gets the
object number from the sortlist<
br>
setObjectSort
(index, objnum
)<
br>
If sortobjects=1 in mapwin.ini, the script luascr/ObjectSort.lua is called when the
Objects in the Block Editor window are refreshed. You can filter objects however
you want, and put the objects you want to display in the list<
br>
Warning:
for custom chunks only, incorrect use can corrupt map file<
br>
createChunk
("CHNK",
size, position
)<
br>
"CHNK" is a four character string NOT used by the editor, size is
the size of the chunk in bytes, position is where in custom chunks it is
inserted
(use
0 to put it at the front
)<
br>
deleteChunk
(chunknum
)<
br>
R
= getChunkValue
(chunknum, offset
)<
br>
setChunkValue
(chunknum, offset,
value)<
br>
offset is offset into
data in bytes, or mappy.CHUNKID or mappy.CHUNKSIZE<
br><
br>
<
p><
a href="#topod">
(top of doc
)<
/a> <
/p>
<
p><
a href="mapwin.htm">
(Back to main documentation
)<
/a> <
/p>