08.11.2012 Views

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

StrCat(res,str);<br />

end;<br />

Result := res;<br />

exports MyMin, DoubleString;<br />

begin<br />

end.<br />

This DLL defines two functions: MyMin that takes two real arguments and returns the<br />

minimum of the two, and DoubleString that doubles the string. Note that you have to be<br />

careful <strong>with</strong> memory management. That is why I declared the resulting string global. Also<br />

notice the use of the cdecl calling convention. You can either use cdecl or stdcall calling<br />

conventions. Once you build the DLL in Delphi you will get a file MyDLL.DLL. This file must be<br />

placed in the running directory of your game. (Or any other place where Windows can find it.)<br />

To use this DLL in <strong>Game</strong> <strong>Maker</strong> you first need to specify the external functions you want to use<br />

and what type of arguments they take. For this there is the following function in GML:<br />

external_define(dll,name,calltype,restype,argnumb,arg1type,<br />

arg2type, ...) Defines an external function. dll is the name of the dll file.<br />

name is the name of the functions. calltype is the calling convention used. For<br />

this use either dll_cdecl or dll_stdcall. restype is the type of the result. For this<br />

use either ty_real or ty_string. argnumb is the number of arguments (0-16).<br />

Next, for each argument you must specify its type. For this again use either<br />

ty_real or ty_string. When there are more than 4 arguments all of them must<br />

be of type ty_real.<br />

This function returns the id of the external function that must be used for calling it. So in the<br />

above example, at the start of the game you would use the following GML code:<br />

{<br />

global.mmm =<br />

external_define('MyDLL.DLL','MyMin',dll_cdecl,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!