Multiplayer Interactive-Fiction Game-Design Blog



Download 8.87 Mb.
Page99/151
Date02.02.2017
Size8.87 Mb.
#15199
1   ...   95   96   97   98   99   100   101   102   ...   151

Overview


This is ALL (hopefully) of the script-code for my multiplayer interactive-fiction game. You can look at this code to come-up with ideas for how to make more interesting non-player characters (NPCs) in the virtual-world or adventure games.

If I am missing anything (which I may be), then look through my source-code or the scripting source-code (available through the CircumReality Integrated Development Environment). (BUGBUG – Download link)


Documentation

Documentation – Standard Library

#importfunc


Used to import functions and methods from C++ code.
A function or method can "import" code from a C/C++ library.

To do this it uses the following code:


#importfunc FuncName




"FuncName" is replaced by a function name that is supported

by the C/C++ application using MIFL.



    1. “Hello world” Application


Steps you through the process of writing a "Hello world" application.


Comparing MIFL to other languages
MIFL is similar to C, C++, Java, and Flash's Actionscript.

If you've used either of these before then you'll find it

very easy to pick up. If you have used other programming

languages, such as Visual Basic, Python, Inform, or TADs then

MIFL will take a bit more getting use to, although it's

still just a programming language.


If you haven't done programming before then I suggest you get

a good book on programming C, C++, Java, or Flash and learn

from that. These tutorials may not be detailed enough to

help you learn how to program from scratch; you're welcome

to try though.



Libraries
A MIFL program (also called a project) is pieced together

using one or more libraries. A library is a

collection of code (and documentation) that the programmer

things fits together. Each library is one file saved on disk.


Building a program from a collection of libaries rather than

one monolithic file has advantages; it allows the programmer to

share code between different projects.


For example: If a programmer writes a lot of code to do fancy

math (like Fourier Transforms) then he/she could put that in

it's own library, separate from the libary for the application-specific

code. Then, if the programmer (or someone else) ever needs

Fourier Transforms in another program, he/she just has to

include the Fourier Transform library in the new program.

A MIFL program (project) will contain a minimum of two libraries:







  • Standard library - This library contains necessary

    functions, globals, method definitions, and property definitions

    for using MIFL. It should always be part of the

    project. (Unless you're a really advanced user and know what you're

    doing.)





  • Context-specific library - This library defines

    functions, etc. necessary for the context of the application.

    For example: If you're using MIFL for an interactive fiction

    application, then an "Interactive Fiction Library" that's common

    to all IF applications will be needed.





  • Application specific library - This is one or more

    libraries specific to your program.

    For example: If you're using MIFL for IF, this would be the

    code for the IF's rooms, items, and NPCs.





To set up the libraries you need for the "Hello world" application:





  1. Click on the Add new libraries menu item under

    the Libraries menu.



  2. In the "Add a new library" page, look for the "Standard library" under

    "Built in libraries". If it's not there (which it shouldn't be) then you

    already have the standard library included (automatically) in your

    project. If the button for "Standard library" exists then press it to

    include the library.





  3. You will also need a library to store the code that displays "Hello world!".

    To do this, press "New library file" in the "Add a new library" page.



  4. In the dialog asking for the file name, type in a name, such

    as "HelloWorld.mfl".



  5. Once you've added the file, you should see the center title of the

    page change to "HelloWorld.mfl" (in yellow text) to indicate that any

    changes you make affect that library. If it doesn't, then

    select HelloWorld.mfl from the Libraries menu.






Functions
The next thing you need to do is create a function. In C, C++, or

Java you type in code like "int Function (int a, double b) {}" to declare

a function. It's much easier to create a function in MIFL.



  1. Select the "Add a new function" menu item

    underneath the "Functions" menu.


  2. A new function will be created and the "Modify function" page will be

    displayed so you can edit it.


  3. In the "Modify function" page, type in a new "Name" for

    the function; change it to "HelloWorld".


  4. If you don't see any entry for "Name" then press

    the "Description" tab in the menu.

    Function names (and object, method, variable, etc. names) cannot

    contain any spaces. They can only contain letters, numbers (but not

    the first character) and underscores.

  5. While you're at it, you can also type in a one-line

    description, like "Displays Hello World!", and even a longer multi-line

    description. The descriptions and help categories are used like

    comments in front of functions. They are also automatically

    included in the help system; all you need to do to see them is

    press the "Rebuild help" button at the bottom of the help

    page.




When you are modifying a function (or object or method) the menu

will be extended to include "Description", "Parameters",

"Code", and "Misc." Pressing these switches to different

sub-pages in the function.





  • Description - Lets you modify the function's

    name, description, and where it appears in help.







  • Parameters - Use this to control what parameters

    are passed into the function and what it returns.







  • Code - This page lets you write the code and

    test it.






  • Misc. - Miscellaneous options, such as moving

    the function to a different library.







Writing code
To actually write the code for the "HelloWorld"

function, press the "Code" tab. The page will

change to show you an edit box for the code.

Type in:

Trace ("Hello world!");


Your "Hello world" program is written. All it does

is pass the string, "Hello world!", into the Trace() function.

The Trace() function (from the "Standard Library") just

writes the string to the debug log. You'll see this in a moment.


To verify that you haven't made any typing mistakes,

press the "Test compile this function" button.

The menu will be extended to show you any errors or warnings;

clicking on one an error or warning will highlight the code

where the error/warning occurred.




Testing your application
To test your application:



  1. Select the Compile menu item under

    the Misc menu. This is different than the

    "Test compile this function" option in the code window

    because it compiles all the functions and objects, as

    opposed to just the one you're working on.




  2. If there were any errors then fix them.
  3. When you're finished with the errors press

    the "Hide errors" link.



  4. Select the "Test compiled code" menu

    item under "Misc".



The "Test compiled code" page will appear. Its window is

divided into several panes:





  • Right - The right side of the page lists

    all the objects, global variables, etc. running in the

    program. Clicking on "Functions" will expand the list

    to show all the functions; your "HelloWorld" function

    will be among them.





  • Left, top - The single-line edit box lets

    you type in code to run. You'll be using this in a minute.







  • Left, center - The "Watch variables" section

    shows you the values of variables in globals, objects, and

    within a function (while you're debugging). For example:

    One variable included in the Standard Library is "Pi";

    if you type "Pi" into one of the fields you'll see

    "3.14159..." appear next to it.







  • Left, bottom - The "Debug trace" shows you

    any run-time errors and anything passed into

    the Trace() function call, which HelloWorld()

    uses.




To run your HelloWorld function:







  1. Type "HelloWorld()" into the single-line

    edit field at the top.





  2. Press "Run this". (Directly under the field.)





That's it, your program has been run. You can see the

results in the "Debug trace" window below. It should

contain:


Execute code: "HelloWorld()"


Hello world!Returns: undefined




The "Hello world!" on the second line is the output of the

Trace() call. "Returns: undefined" tells you what the

function returned, which was nothing.
Comments
I haven't used any comments in my sample code, but

rest assured, MIFL allows for comments. There are two types,

and act just like comments in C, C++, Java, and ActionScript:





  • // comment - If you use a double-slash then

    all the text to the end of the line will be ignored by

    the compiler.





  • /* comment */ - If you use a /* then

    all the text until the next */ will be ignored by

    the compiler.






    1. Download 8.87 Mb.

      Share with your friends:
1   ...   95   96   97   98   99   100   101   102   ...   151




The database is protected by copyright ©ininet.org 2024
send message

    Main page