1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/*
$Id$
Copyright (C) 2001 Alexandre Courbot
Part of the Adonthell Project http://adonthell.linuxgames.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/*!
\page page8 Writing mapcharacter schedules
\section mcharsched0 Generalities
A mapcharacter schedule file should always be placed in the \e
script/schedules/mapcharacters directory in the %game hierarchy. It
should contain a single class, named like the module. A schedule is
attached to a mapcharacter by the mapcharacter::set_schedule ()
method. See it's documentation for more details. You should be
particularly careful that the argument list given to
mapcharacter::set_schedule () \e has to be a Python tuple
containing ONLY Python strings or integers.
\section mcharsched1 Arguments passed to __init__ ()
When you call mapcharacter::set_schedule (), the first argument
passed to the class constructor is a reference to the mapcharacter
that called this method. This parameter should be saved as it will
most likely be used during the run () method to control the
mapcharacter. Then follow the arguments inside the tuple (optionally)
passed to mapcharacter::set_schedule ().
\section mcharsched2 Arguments passed to run ()
No arguments are passed to the run () method.
\section mcharsched3 Structure of a mapcharacter schedule file
Here is what a mapcharacter schedule file should ideally look like:
\verbatim
#
# (C) Copyright <year> <your name>
# Part of the Adonthell Project http://adonthell.linuxgames.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY.
#
# See the COPYING file for more details
#
#
# <description of the schedule>
#
<do your imports here>
class myschedule:
# Parameters:
# Description of myparameter1
# Description of myparameter2
def __init__ (self, mapcharacterinstance, myparameter1, myparameter2):
self.myself = mapcharacterinstance
<do your other initialisation here>
def run (self):
<mapcharacter control>
def __del__ (self)
<eventual cleanup>
\endverbatim
\section mcharsched4 Storing variables
It is unsafe to store variables in the class instance others than
those passed to the __init__ method. When a mapcharacter's
schedule is state-saved, only the schedule filename and it's
initialisation arguments (the Python tuple passed to
mapcharacter::set_schedule ()) are saved. So, if you create variables
in the \e self object, do not expect them to survive %game
saving/loading. A safe approach is to make use of the storage class,
from which mapcharacter inherits, to store your persistant variables.
Then they are automatically saved together with the mapcharacter.
*/
|