evennia.contrib.tutorial_examples package

Submodules

evennia.contrib.tutorial_examples.bodyfunctions module

Example script for testing. This adds a simple timer that has your character make observations and notices at irregular intervals.

To test, use

@script me = tutorial_examples.bodyfunctions.BodyFunctions

The script will only send messages to the object it is stored on, so make sure to put it on yourself or you won’t see any messages!

class evennia.contrib.tutorial_examples.bodyfunctions.BodyFunctions(*args, **kwargs)[source]

Bases: evennia.scripts.scripts.DefaultScript

This class defines the script itself

exception DoesNotExist

Bases: evennia.scripts.scripts.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.MultipleObjectsReturned

_meta = <Options for BodyFunctions>
at_repeat()[source]

This gets called every self.interval seconds. We make a random check here so as to only return 33% of the time.

at_script_creation()[source]

Only called once, when script is first created.

path = 'evennia.contrib.tutorial_examples.bodyfunctions.BodyFunctions'
send_random_message()[source]
typename = 'BodyFunctions'

evennia.contrib.tutorial_examples.cmdset_red_button module

This defines the cmdset for the red_button. Here we have defined the commands and the cmdset in the same module, but if you have many different commands to merge it is often better to define the cmdset separately, picking and choosing from among the available commands as to what should be included in the cmdset - this way you can often re-use the commands too.

class evennia.contrib.tutorial_examples.cmdset_red_button.BlindCmdSet(cmdsetobj=None, key=None)[source]

Bases: evennia.commands.cmdset.CmdSet

This is the cmdset added to the account when the button is pushed.

at_cmdset_creation()[source]

Setup the blind cmdset

key = 'BlindCmdSet'
mergetype = 'Replace'
no_exits = True
no_objs = True
path = 'evennia.contrib.tutorial_examples.cmdset_red_button.BlindCmdSet'
class evennia.contrib.tutorial_examples.cmdset_red_button.CmdBlindHelp(**kwargs)[source]

Bases: evennia.commands.command.Command

Help function while in the blinded state

Usage:

help

_keyaliases = ('help', 'h')
_matchset = {'h', 'help'}
aliases = ['h']
func()[source]

Give a message.

help_category = 'general'
key = 'help'
lock_storage = 'cmd:all()'
locks = 'cmd:all()'
search_index_entry = {'aliases': 'h', 'category': 'general', 'key': 'help', 'tags': '', 'text': '\n Help function while in the blinded state\n\n Usage:\n help\n\n '}
class evennia.contrib.tutorial_examples.cmdset_red_button.CmdBlindLook(**kwargs)[source]

Bases: evennia.commands.command.Command

Looking around in darkness

Usage:

look <obj>

… not that there’s much to see in the dark.

_keyaliases = ('get', 'feel', 'examine', 'listen', 'ex', 'l', 'look')
_matchset = {'ex', 'examine', 'feel', 'get', 'l', 'listen', 'look'}
aliases = ['get', 'feel', 'examine', 'listen', 'ex', 'l']
func()[source]

This replaces all the senses when blinded.

help_category = 'general'
key = 'look'
lock_storage = 'cmd:all()'
locks = 'cmd:all()'
search_index_entry = {'aliases': 'get feel examine listen ex l', 'category': 'general', 'key': 'look', 'tags': '', 'text': "\n Looking around in darkness\n\n Usage:\n look <obj>\n\n ... not that there's much to see in the dark.\n\n "}
class evennia.contrib.tutorial_examples.cmdset_red_button.CmdCloseLid(**kwargs)[source]

Bases: evennia.commands.command.Command

close the lid

Usage:

close lid

Closes the lid of the red button.

_keyaliases = ('close lid', 'close')
_matchset = {'close', 'close lid'}
aliases = ['close']
func()[source]

Close the lid

help_category = 'general'
key = 'close lid'
lock_storage = 'cmd:all()'
locks = 'cmd:all()'
search_index_entry = {'aliases': 'close', 'category': 'general', 'key': 'close lid', 'tags': '', 'text': '\n close the lid\n\n Usage:\n close lid\n\n Closes the lid of the red button.\n '}
class evennia.contrib.tutorial_examples.cmdset_red_button.CmdNudge(**kwargs)[source]

Bases: evennia.commands.command.Command

Try to nudge the button’s lid

Usage:

nudge lid

This command will have you try to push the lid of the button away.

_keyaliases = ('nudge lid', 'nudge')
_matchset = {'nudge', 'nudge lid'}
aliases = ['nudge']
func()[source]

nudge the lid. Random chance of success to open it.

help_category = 'general'
key = 'nudge lid'
lock_storage = 'cmd:all()'
locks = 'cmd:all()'
search_index_entry = {'aliases': 'nudge', 'category': 'general', 'key': 'nudge lid', 'tags': '', 'text': "\n Try to nudge the button's lid\n\n Usage:\n nudge lid\n\n This command will have you try to\n push the lid of the button away.\n "}
class evennia.contrib.tutorial_examples.cmdset_red_button.CmdOpenLid(**kwargs)[source]

Bases: evennia.commands.command.Command

open lid

Usage:

open lid

_keyaliases = ('open lid', 'open', 'open button')
_matchset = {'open', 'open button', 'open lid'}
aliases = ['open', 'open button']
func()[source]

simply call the right function.

help_category = 'general'
key = 'open lid'
lock_storage = 'cmd:all()'
locks = 'cmd:all()'
search_index_entry = {'aliases': 'open open button', 'category': 'general', 'key': 'open lid', 'tags': '', 'text': '\n open lid\n\n Usage:\n open lid\n\n '}
class evennia.contrib.tutorial_examples.cmdset_red_button.CmdPush(**kwargs)[source]

Bases: evennia.commands.command.Command

Push the red button

Usage:

push button

_keyaliases = ('press', 'push', 'push button', 'press button')
_matchset = {'press', 'press button', 'push', 'push button'}
aliases = ['press', 'push', 'press button']
func()[source]

Note that we choose to implement this with checking for if the lid is open/closed. This is because this command is likely to be tried regardless of the state of the lid.

An alternative would be to make two versions of this command and tuck them into the cmdset linked to the Open and Closed lid-state respectively.

help_category = 'general'
key = 'push button'
lock_storage = 'cmd:all()'
locks = 'cmd:all()'
search_index_entry = {'aliases': 'press push press button', 'category': 'general', 'key': 'push button', 'tags': '', 'text': '\n Push the red button\n\n Usage:\n push button\n\n '}
class evennia.contrib.tutorial_examples.cmdset_red_button.CmdSmashGlass(**kwargs)[source]

Bases: evennia.commands.command.Command

smash glass

Usage:

smash glass

Try to smash the glass of the button.

_keyaliases = ('break lid', 'smash glass', 'smash lid', 'smash')
_matchset = {'break lid', 'smash', 'smash glass', 'smash lid'}
aliases = ['break lid', 'smash lid', 'smash']
func()[source]

The lid won’t open, but there is a small chance of causing the lamp to break.

help_category = 'general'
key = 'smash glass'
lock_storage = 'cmd:all()'
locks = 'cmd:all()'
search_index_entry = {'aliases': 'break lid smash lid smash', 'category': 'general', 'key': 'smash glass', 'tags': '', 'text': '\n smash glass\n\n Usage:\n smash glass\n\n Try to smash the glass of the button.\n '}
class evennia.contrib.tutorial_examples.cmdset_red_button.DefaultCmdSet(cmdsetobj=None, key=None)[source]

Bases: evennia.commands.cmdset.CmdSet

The default cmdset always sits on the button object and whereas other command sets may be added/merge onto it and hide it, removing them will always bring it back. It’s added to the object using obj.cmdset.add_default().

at_cmdset_creation()[source]

Init the cmdset

key = 'RedButtonDefault'
mergetype = 'Union'
path = 'evennia.contrib.tutorial_examples.cmdset_red_button.DefaultCmdSet'
class evennia.contrib.tutorial_examples.cmdset_red_button.LidClosedCmdSet(cmdsetobj=None, key=None)[source]

Bases: evennia.commands.cmdset.CmdSet

A simple cmdset tied to the redbutton object.

It contains the commands that launches the other command sets, making the red button a self-contained item (i.e. you don’t have to manually add any scripts etc to it when creating it).

at_cmdset_creation()[source]

Populates the cmdset when it is instantiated.

key = 'LidClosedCmdSet'
key_mergetype = {'LidOpenCmdSet': 'Replace'}
path = 'evennia.contrib.tutorial_examples.cmdset_red_button.LidClosedCmdSet'
class evennia.contrib.tutorial_examples.cmdset_red_button.LidOpenCmdSet(cmdsetobj=None, key=None)[source]

Bases: evennia.commands.cmdset.CmdSet

This is the opposite of the Closed cmdset.

at_cmdset_creation()[source]

setup the cmdset (just one command)

key = 'LidOpenCmdSet'
key_mergetype = {'LidClosedCmdSet': 'Replace'}
path = 'evennia.contrib.tutorial_examples.cmdset_red_button.LidOpenCmdSet'

evennia.contrib.tutorial_examples.example_batch_code module

evennia.contrib.tutorial_examples.red_button module

This is a more advanced example object. It combines functions from script.examples as well as commands.examples to make an interactive button typeclass.

Create this button with

@create/drop examples.red_button.RedButton

Note that you must drop the button before you can see its messages!

class evennia.contrib.tutorial_examples.red_button.RedButton(*args, **kwargs)[source]

Bases: evennia.objects.objects.DefaultObject

This class describes an evil red button. It will use the script definition in contrib/examples/red_button_scripts to blink at regular intervals. It also uses a series of script and commands to handle pushing the button and causing effects when doing so.

The following attributes can be set on the button:

desc_lid_open - description when lid is open desc_lid_closed - description when lid is closed desc_lamp_broken - description when lamp is broken

exception DoesNotExist

Bases: evennia.objects.objects.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.objects.objects.MultipleObjectsReturned

_meta = <Options for RedButton>
at_object_creation()[source]

This function is called when object is created. Use this instead of e.g. __init__.

The script system will regularly call this function to make the button blink. Now and then it won’t blink at all though, to add some randomness to how often the message is echoed.

break_lamp(feedback=True)[source]

Breaks the lamp in the button, stopping it from blinking.

Parameters

feedback (bool) – Show a message about breaking the lamp.

close_lid()[source]

Close the glass lid. This validates all scripts on the button, which means that scripts only being valid when the lid is open will go away automatically.

open_lid()[source]

Opens the glass lid and start the timer so it will soon close again.

path = 'evennia.contrib.tutorial_examples.red_button.RedButton'
press_button(pobject)[source]

Someone was foolish enough to press the button!

Parameters

pobject (Object) – The person pressing the button

typename = 'RedButton'

evennia.contrib.tutorial_examples.red_button_scripts module

Example of scripts.

These are scripts intended for a particular object - the red_button object type in contrib/examples. A few variations on uses of scripts are included.

class evennia.contrib.tutorial_examples.red_button_scripts.BlindedState(*args, **kwargs)[source]

Bases: evennia.scripts.scripts.DefaultScript

This is a timed state.

This adds a (very limited) cmdset TO THE ACCOUNT, during a certain time, after which the script will close and all functions are restored. It’s up to the function starting the script to actually set it on the right account object.

exception DoesNotExist

Bases: evennia.scripts.scripts.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.MultipleObjectsReturned

_meta = <Options for BlindedState>
at_script_creation()[source]

We set up the script here.

at_start()[source]

We want to add the cmdset to the linked object.

Note that the RedButtonBlind cmdset is defined to completly replace the other cmdsets on the stack while it is active (this means that while blinded, only operations in this cmdset will be possible for the account to perform). It is however not persistent, so should there be a bug in it, we just need to restart the server to clear out of it during development.

at_stop()[source]

It’s important that we clear out that blinded cmdset when we are done!

path = 'evennia.contrib.tutorial_examples.red_button_scripts.BlindedState'
typename = 'BlindedState'
class evennia.contrib.tutorial_examples.red_button_scripts.BlinkButtonEvent(*args, **kwargs)[source]

Bases: evennia.scripts.scripts.DefaultScript

This timed script lets the button flash at regular intervals.

exception DoesNotExist

Bases: evennia.scripts.scripts.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.MultipleObjectsReturned

_meta = <Options for BlinkButtonEvent>
at_repeat()[source]

Called every self.interval seconds. Makes the lamp in the button blink.

at_script_creation()[source]

Sets things up. We want the button’s lamp to blink at regular intervals, unless it’s broken (can happen if you try to smash the glass, say).

is_valid()[source]

Button will keep blinking unless it is broken.

path = 'evennia.contrib.tutorial_examples.red_button_scripts.BlinkButtonEvent'
typename = 'BlinkButtonEvent'
class evennia.contrib.tutorial_examples.red_button_scripts.CloseLidEvent(*args, **kwargs)[source]

Bases: evennia.scripts.scripts.DefaultScript

This event closes the glass lid over the button some time after it was opened. It’s a one-off script that should be started/created when the lid is opened.

exception DoesNotExist

Bases: evennia.scripts.scripts.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.MultipleObjectsReturned

_meta = <Options for CloseLidEvent>
at_repeat()[source]

Called after self.interval seconds. It closes the lid. Before this method is called, self.is_valid() is automatically checked, so there is no need to check this manually.

at_script_creation()[source]

Called when script object is first created. Sets things up. We want to have a lid on the button that the user can pull aside in order to make the button ‘pressable’. But after a set time that lid should auto-close again, making the button safe from pressing (and deleting this command).

is_valid()[source]

This script can only operate if the lid is open; if it is already closed, the script is clearly invalid.

Note that we are here relying on an self.obj being defined (and being a RedButton object) - this we should be able to expect since this type of script is always tied to one individual red button object and not having it would be an error.

path = 'evennia.contrib.tutorial_examples.red_button_scripts.CloseLidEvent'
typename = 'CloseLidEvent'
class evennia.contrib.tutorial_examples.red_button_scripts.ClosedLidState(*args, **kwargs)[source]

Bases: evennia.scripts.scripts.DefaultScript

This manages the cmdset for the “closed” button state. What this means is that while this script is valid, we add the RedButtonClosed cmdset to it (with commands like open, nudge lid etc)

exception DoesNotExist

Bases: evennia.scripts.scripts.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.MultipleObjectsReturned

_meta = <Options for ClosedLidState>
at_script_creation()[source]

Called when script first created.

at_start()[source]

This is called once every server restart, so we want to add the (memory-resident) cmdset to the object here. is_valid is automatically checked so we don’t need to worry about adding the script to an open lid.

at_stop()[source]

When the script stops we must make sure to clean up after us.

is_valid()[source]

The script is only valid while the lid is closed. self.obj is the red_button on which this script is defined.

path = 'evennia.contrib.tutorial_examples.red_button_scripts.ClosedLidState'
typename = 'ClosedLidState'
class evennia.contrib.tutorial_examples.red_button_scripts.DeactivateButtonEvent(*args, **kwargs)[source]

Bases: evennia.scripts.scripts.DefaultScript

This deactivates the button for a short while (it won’t blink, won’t close its lid etc). It is meant to be called when the button is pushed and run as long as the blinded effect lasts. We cannot put these methods in the AddBlindedCmdSet script since that script is defined on the account whereas this one must be defined on the button.

exception DoesNotExist

Bases: evennia.scripts.scripts.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.MultipleObjectsReturned

_meta = <Options for DeactivateButtonEvent>
at_repeat()[source]

When this is called, reset the functionality of the button.

at_script_creation()[source]

Sets things up.

at_start()[source]

Deactivate the button. Observe that this method is always called directly, regardless of the value of self.start_delay (that just controls when at_repeat() is called)

path = 'evennia.contrib.tutorial_examples.red_button_scripts.DeactivateButtonEvent'
typename = 'DeactivateButtonEvent'
class evennia.contrib.tutorial_examples.red_button_scripts.OpenLidState(*args, **kwargs)[source]

Bases: evennia.scripts.scripts.DefaultScript

This manages the cmdset for the “open” button state. This will add the RedButtonOpen

exception DoesNotExist

Bases: evennia.scripts.scripts.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.MultipleObjectsReturned

_meta = <Options for OpenLidState>
at_script_creation()[source]

Called when script first created.

at_start()[source]

This is called once every server restart, so we want to add the (memory-resident) cmdset to the object here. is_valid is automatically checked, so we don’t need to worry about adding the cmdset to a closed lid-button.

at_stop()[source]

When the script stops (like if the lid is closed again) we must make sure to clean up after us.

is_valid()[source]

The script is only valid while the lid is open. self.obj is the red_button on which this script is defined.

path = 'evennia.contrib.tutorial_examples.red_button_scripts.OpenLidState'
typename = 'OpenLidState'

evennia.contrib.tutorial_examples.tests module

class evennia.contrib.tutorial_examples.tests.TestBodyFunctions(methodName='runTest')[source]

Bases: evennia.utils.test_resources.EvenniaTest

script_typeclass

alias of evennia.contrib.tutorial_examples.bodyfunctions.BodyFunctions

setUp()[source]

Sets up testing environment

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_at_repeat(mock_random)[source]

test that no message will be sent when below the 66% threshold

test_send_random_message(mock_random)[source]

Test that correct message is sent for each random value