?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. <html>
  2.  
  3. <head>
  4. <title>MappyWin32 Lua scripting documentation</title>
  5. </head>
  6.  
  7. <body bgcolor="#cccccc" text="#000000" link="#0000ff" vlink="#0000aa">
  8.  
  9. <p><a name="topod"></a></p>
  10. <h2>MappyWin32 Lua scripting documentation</h2>
  11. <br>
  12. &nbsp;<strong>Lua scripts</strong>. Added in 1.3.22, you can write
  13. scripts to perform functions in the editor such as exporting/importing
  14. graphics, maps and other data from custom formats, editing the map or
  15. blocks, performing a custom task and
  16. many other things. The scripts are written in a language called LUA
  17. (see www.lua.org), see the copyright notice in the luascr folder.
  18. Lua scripts can either be put in the luascr folder, and then set
  19. the LUA values in the mapwin.ini file to add them to the Custom menu.
  20. Alternatively, you can drag and drop a file ending with '.lua'
  21. onto MappyWin32 to run it.<br><br>
  22. &nbsp;I'd like to thank Robbob (Autofringe, Random distribution) and
  23. Jerzy Kut (Export binary file) for their help with lua.
  24. I have included some example scripts in the luascr folder (not all
  25. of these are listed in the custom menu), look
  26. at them in a text editor to see how they work, I am a novice with
  27. Lua, so they are quite basic.
  28. Load a test map and run them to see what they do, most of them
  29. give a brief summary of what they do before they start.
  30. You do not need to restart Mappy if you modify a script. You can
  31. override the functions in the file menu with lua scripts to fully
  32. customize loading and saving of maps (see mapwin.ini).
  33. MappyWin32 extends LUA with these functions (don't forget
  34. to prefix functions and values with 'mappy.' see the .lua files in
  35. the luascr folder):<br><br>
  36. <strong>General functions:</strong><br>
  37. R = getValue (VALUE_ID)<br>
  38. &nbsp;where VALUE_ID is one of:<br>
  39. MAPWIDTH,
  40. MAPHEIGHT,
  41. BLOCKDEPTH,
  42. BLOCKWIDTH,
  43. BLOCKHEIGHT,
  44. NUMBLOCKSTR,
  45. NUMBLOCKGFX,
  46. BLOCKGAPX,
  47. BLOCKGAPY,
  48. BLOCKSTAGGERX,
  49. BLOCKSTAGGERY,
  50. CLICKMASK,
  51. TRANS8,
  52. TRANSRED,
  53. TRANSGREEN,
  54. TRANSBLUE,
  55. CURLAYER,
  56. CURBLOCK,
  57. CURANIM,
  58. CURBRUSH,
  59. MOUSEBLOCKX,
  60. MOUSEBLOCKY,
  61. GETBLOCKMODE,
  62. PALETTEARGB+index,
  63. NUMBLOCKANIM,
  64. XMAPOFFSET,
  65. YMAPOFFSET,
  66. MAPFILENAME,
  67. MAPWINPATH,
  68. MAPTYPE,
  69. MAPWINVERSION,
  70. NUMBRUSHES,
  71. NUMLAYERS,
  72. CUROBJECT,
  73. NUMOBJECTS,
  74. CMDLINE,
  75. NUMCHUNKS,
  76. CURGFX,
  77. BEWINDOWTYPE<br><br>
  78.  
  79. setValue (VALUE_ID, SETVALUE)<br>
  80. &nbsp;where VALUE_ID is one of:<br>
  81. TRANS8,
  82. TRANSRED,
  83. TRANSGREEN,
  84. TRANSBLUE,
  85. PALETTEARGB+index,
  86. GETBLOCKMODE,
  87. CURLAYER,
  88. CURBLOCK,
  89. CURANIM,
  90. CURBRUSH,
  91. XMAPOFFSET,
  92. YMAPOFFSET,
  93. MAPFILENAME,
  94. CUROBJECT,
  95. MAPTYPE,
  96. CURGFX,
  97. BEWINDOWTYPE<br><br>
  98. R = shiftVal (VALUE, SHIFT) negative shift is left, positive is right<br>
  99. R = andVal (VALUE1, VALUE2)<br>
  100. R = orVal (VALUE1, VALUE2)<br><br>
  101.  
  102.  
  103. <strong>Block functions:</strong><br>
  104. R = getBlock (X, Y [,L])<br>
  105. &nbsp;where X is the x coord in blocks,
  106. and Y is y coord in blocks, L is the optional layer number, omit it for current layer<br><br>
  107. setBlock (X, Y, B [,L])<br>
  108. &nbsp;where X is the x coord in blocks, and Y is y coord in blocks, and B is the block index,
  109. L is the optional layer number, omit it for current layer (see 'Solid rectangle.lua' for an example)<br><br>
  110. R = getBlockValue (B, VALUE_ID)<br>
  111. &nbsp;where B is the block index, and VALUE_ID is one of:<br>
  112. BLKBG,
  113. BLKFG1,
  114. BLKFG2,
  115. BLKFG3,
  116. BLKUSER1,
  117. BLKUSER2,
  118. BLKUSER3,
  119. BLKUSER4,
  120. BLKUSER5,
  121. BLKUSER6,
  122. BLKUSER7,
  123. BLKFLAG1,
  124. BLKFLAG2,
  125. BLKFLAG3,
  126. BLKFLAG4,
  127. BLKFLAG5,
  128. BLKFLAG6,
  129. BLKFLAG7,
  130. BLKFLAG8<br><br>
  131.  
  132. setBlockValue (B, VALUE_ID, VALUE)<br>
  133. &nbsp;where B is the block index, and VALUE_ID is one of:<br>
  134. BLKBG,
  135. BLKFG1,
  136. BLKFG2,
  137. BLKFG3,
  138. BLKUSER1,
  139. BLKUSER2,
  140. BLKUSER3,
  141. BLKUSER4,
  142. BLKUSER5,
  143. BLKUSER6,
  144. BLKUSER7,
  145. BLKFLAG1,
  146. BLKFLAG2,
  147. BLKFLAG3,
  148. BLKFLAG4,
  149. BLKFLAG5,
  150. BLKFLAG6,
  151. BLKFLAG7,
  152. BLKFLAG8<br>
  153. and VALUE is the value to write (flags are 0 or 1) see 'Tile graphic test.lua'<br><br>
  154. createBlock (B)<br>
  155. &nbsp;where B is the block index to insert the new block at<br><br>
  156. deleteBlock (B)<br>
  157. &nbsp;where B is the block index to remove<br>
  158. R = getBlockSort (index)<br>
  159. Gets the block number from the sortlist<br>
  160. setBlockSort (index, B)<br>
  161. If sortblocks=1 in mapwin.ini, the script luascr/BlockSort.lua is called when the
  162. Blocks in the Block Editor window are refreshed. You can filter blocks however
  163. you want, and put the blocks you want to display in the list<br>
  164. <br>
  165.  
  166. <br><br>
  167.  
  168. <strong>Layer functions:</strong><br>
  169. copyLayer (SOURCE, DEST)<br>
  170. &nbsp; where SOURCE is the layer to copy from (0 to 7 or MPY_UNDO), and DEST is the
  171. layer to copy to (0 to 7 or MPY_UNDO) if you are changing the current layer, use:<br>
  172. mappy.copyLayer(mappy.getValue(mappy.CURLAYER),mappy.MPY_UNDO)<br>
  173. to enable undo.<br><br>
  174. createLayer (layer)<br>
  175. deleteLayer (layer)<br>
  176. <br>
  177.  
  178. <strong>Graphics functions:</strong><br>
  179. createGraphic (G)<br>
  180. &nbsp;where G is the graphic index to insert the new graphic at<br><br>
  181. deleteGraphic (G)<br>
  182. &nbsp;where G is the graphic index to remove<br><br>
  183. In the following A is Alpha, R is Red, G is Green, B is Blue, all values between
  184. 0 (none) and 255 (max), 0 Alpha is transparent, 255 is solid.<br>
  185. A,R,G,B = getPixel (X, Y, G)<br>
  186. &nbsp;where X, Y is pixel coord within the graphic, G is the graphic index<br><br>
  187. setPixel (X, Y, G, A, R, G, B) or<br>
  188. setPixel (X, Y, G, INDEX)<br>
  189. &nbsp;where INDEX is the palette index 0 to 255)<br><br>
  190. R = importGraphics ("FILENAME", GFXPOS, AMOUNT)<br>
  191. &nbsp; where GFXPOS is the graphic number to start importing at, and AMOUNT
  192. is the number of tiles to import. AMOUNT can be 0 for all.<br><br>
  193.  
  194. <strong>Dialogue/Requester functions:</strong><br>
  195. R = msgBox ("TITLE", "MESSAGE", TYPE, ICON)<br>
  196. &nbsp;where TYPE is one of:<br>
  197. MMB_OK,
  198. MMB_OKCANCEL,
  199. MMB_YESNOCANCEL,<br>
  200. and ICON is one of:<br>
  201. MMB_ICONNONE,
  202. MMB_ICONINFO,
  203. MMB_ICONQUESTION,
  204. MMB_ICONEXCLAMATION<br>
  205. returns one of:<br>
  206. MMB_CANCEL,
  207. MMB_YES,
  208. MMB_NO<br><br>
  209. R, "FILENAME" = fileRequester ("PATH", "DESCRIPTION", "EXTENSION", TYPE)<br>
  210. &nbsp;where PATH is the starting folder (try "."), DESCRIPTION is what
  211. appears in the 'Save as type' box, EXTENSION is a properly formatted mask
  212. for file extensions (ie: "*.FMP" or "*.FMP;*.MAP"). And TYPE is either
  213. MMB_OPEN or MMB_SAVE<br>
  214. returns R, either MMB_OK or MMB_CANCEL, also "FILENAME"<br><br>
  215. R = doDialogue ("TITLE", "MESSAGE", "STRING", TYPE)<br>
  216. &nbsp;TITLE should contain 14 or fewer characters. where TYPE is either MMB_DIALOGUE1 or MMB_DIALOGUE2, type 1 returns
  217. MMB_OK or MMB_CANCEL and one string, type 2 returns MMB_OK or MMB_CANCEL
  218. and as many strings as there were commas plus 1 (ie: hello,1,2,3 would
  219. return four strings "hello" "1" "2" and "3")<br>
  220. <strong>Complex dialogue boxes:</strong><br>
  221. R = doDialogue ("DLGPROC")<br>
  222. &nbsp; "DLGPROC" is the name of the handler for dialogue messages.
  223. See the scripts
  224. 'Dialogue Example.lua' and 'Dialogue Proc.lua'. Some knowledge of Win32
  225. dialogues is required.<br>
  226. createDialogue ("Title", STYLE, X, Y, W, H, NUMCONTROLS)<br>
  227. &nbsp; creates a custom dialogue, STYLE can be 0 for default. See the scripts
  228. 'Dialogue Example.lua' and 'Dialogue Proc.lua'. Some knowledge of Win32
  229. dialogues is required.<br>
  230. addDialogueItem ("Title", STYLE, X, Y, W, H, IDC, TYPE)<br>
  231. &nbsp; See defines in 'Dialogue Example.lua'<br>
  232. hwnd, msg, wParam, lParam = getDialogueParam ()<br>
  233. &nbsp; See 'Dialogue Proc.lua', note: Proc is sent idc == 99 on creation so
  234. lists can be populated and labels changed etc<br>
  235. checkDlgButton (IDC, STATUS)<br>
  236. &nbsp; Sets button IDC to STATUS<br>
  237. R = isDlgButtonChecked (IDC)<br>
  238. &nbsp; R is STATUS of button IDC<br>
  239. R = getDlgItemText (IDC)<br>
  240. &nbsp; R is text of item as a string<br>
  241. setDlgItemText (IDC, "TEXT")<br>
  242. &nbsp; TEXT is new text of item as a string<br>
  243. R = sendDlgItemMessage (IDC, MSG, WPARAM, LPARAM)<br>
  244. &nbsp; Get and Set information for all types of buttons etc. Allows
  245. setting and retrieving see
  246. any tutorial on Win32 dialogues and DlgItemMessage<br>
  247. <br><br>
  248.  
  249. <strong>Anim functions:</strong><br>
  250. createAnim (animnum)<br>
  251. deleteAnim (animnum)<br>
  252. R = getAnimFrame (animnum, framenum)<br>
  253. 'framenum' can be ANMREFFRAME<br>
  254. setAnimFrame (animnum, framenum, blockval)<br>
  255. 'framenum' can be ANMREFFRAME<br>
  256. R = numAnimFrames (animnum)<br>
  257. insertAnimFrame (animnum, framenum, blockval)<br>
  258. cutAnimFrame (animnum, framenum)<br>
  259. R = numAnimFrames (animnum)<br>
  260. R = getAnimValue (VAL)<br>
  261. VAL is:<br>
  262. ANMDELAY, ANMCOUNT, ANMTYPE, ANMUSER, ANMCURFRAME<br>
  263. setAnimValue (VAL, val)<br>
  264. VAL is:<br>
  265. ANMDELAY, ANMCOUNT, ANMTYPE, ANMUSER, ANMCURFRAME<br>
  266. <br>
  267. <strong>Brush functions:</strong><br>
  268. createBrush (brshnum, x, y, w, h)<br>
  269. deleteBrush (brshnum)<br>
  270. renameBrush (brshnum, "Brushname")<br>
  271. R = getBrushBlock (brshnum, x, y)<br>
  272. setBrushBlock (brshnum, x, y, blk)<br>
  273. R = getBrushValue (VAL)<br>
  274. VAL is:<br>
  275. BRUSHWIDTH, BRUSHHEIGHT, BRUSHNAME<br>
  276. <br>
  277. <strong>TextString functions:</strong><br>
  278. getTextString (index)<br>
  279. setTextString (index, "Text")<br>
  280. <br>
  281. <strong>Map/System functions:</strong><br>
  282. newMap (mapwidth, mapheight, mapdepth, tilewidth, tileheight, [tilegapx, tilegapy, tilestaggerx, tilestaggery, maptype])<br>
  283. closeMap ()<br>
  284. openFMP (["FILENAME"])<br>
  285. saveFMP (["FILENAME"])<br>
  286. &nbsp; if no "filename" supplied, current filename is used. On saving,
  287. use mappy.setValue(mappy.MAPFILENAME, "filename") if you want to change the name<br>
  288. resizeMap (WIDTH, HEIGHT, CENTERING)<br>
  289. &nbsp; CENTERING is from 1 to 9 as in the MapTools:Resize dialogue<br>
  290. updateScreen ()<br>
  291. &nbsp; call this to refresh the display after altering a layer<br><br>
  292. shellExecute (action, file, params, dir, style)<br>
  293. &nbsp; call an external programme, example:
  294. mappy.shellExecute ("open", "notepad", "mapwin.ini", "c:/mapwin148/", 0)<br>
  295. sendMessage (code, 0)<br>
  296. code is one of the key shortcuts listed in mapwin.htm<br>
  297. for example sendMessage (119, 0) shows the helpfile<br>
  298. renameMenuItem (code, "Name")<br>
  299. &nbsp; code is one of the key shortcuts listed in mapwin.htm. "Name" is the new name for the menu item<br>
  300. moveWindow (WINDOW, x, y, width, height)<br>
  301. &nbsp; added (WINDOW = MPY_MAINWINDOW, MPY_MAPWINDOW or MPY_BLOCKWINDOW)<br>
  302. <br>
  303. <strong>Object functions (Pro only):</strong><br>
  304. createObject (position)<br>
  305. deleteObject (objnum)<br>
  306. R = getObjectValue (objnum, VALUE_ID)<br>
  307. setObjectValue (objnum, VALUE_ID, objval)<br>
  308. VALUE_ID for the above can be one of:
  309. OBJXPOS,
  310. OBJYPOS,
  311. OBJGFXID,
  312. OBJTILEID,
  313. OBJGXOFF,
  314. OBJGYOFF,
  315. OBJGWIDTH,
  316. OBJGHEIGHT,
  317. OBJGHANDLEXOFF,
  318. OBJGHANDLEYOFF,
  319. OBJSHOW,
  320. OBJUSER1,
  321. OBJUSER2,
  322. OBJUSER3,
  323. OBJUSER4,
  324. OBJUSER5,
  325. OBJUSER6,
  326. OBJUSER7,
  327. OBJFLAGS<br>
  328. R = getObjectFilename (index)<br>
  329. Gets the string for the image filename displayed in the Object Properties dialogue,
  330. 'index' is the position in the list<br>
  331. setObjectFilename (index, "Filename")<br>
  332. Sets the string for the image filename displayed in the Object Properties dialogue,
  333. 'index' is the position in the list<br>
  334. R = getObjectSort (index)<br>
  335. Gets the object number from the sortlist<br>
  336. setObjectSort (index, objnum)<br>
  337. If sortobjects=1 in mapwin.ini, the script luascr/ObjectSort.lua is called when the
  338. Objects in the Block Editor window are refreshed. You can filter objects however
  339. you want, and put the objects you want to display in the list<br>
  340. <br>
  341. <strong>Chunk functions:</strong><br>
  342. Warning: for custom chunks only, incorrect use can corrupt map file<br>
  343. createChunk ("CHNK", size, position)<br>
  344. &nbsp; "CHNK" is a four character string NOT used by the editor, size is
  345. the size of the chunk in bytes, position is where in custom chunks it is
  346. inserted (use 0 to put it at the front)<br>
  347. deleteChunk (chunknum)<br>
  348. R = getChunkValue (chunknum, offset)<br>
  349. setChunkValue (chunknum, offset, value)<br>
  350. &nbsp; offset is offset into data in bytes, or mappy.CHUNKID or mappy.CHUNKSIZE<br><br>
  351.  
  352. <p><a href="#topod">(top of doc)</a> </p>
  353.  
  354. <p><a href="mapwin.htm">(Back to main documentation)</a> </p>
  355.  
  356. </body>
  357. </html>
  358.