evennia.contrib.tutorials.red_button.red_button¶
Red Button
Griatch - 2011
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 tutorials.red_button.RedButton
Note that you must drop the button before you can see its messages!
Technical¶
The button’s functionality is controlled by CmdSets that gets added and removed depending on the ‘state’ the button is in.
Lid-closed state: In this state the button is covered by a glass cover and trying to ‘push’ it will fail. You can ‘nudge’, ‘smash’ or ‘open’ the lid.
Lid-open state: In this state the lid is open but will close again after a certain time. Using ‘push’ now will press the button and trigger the Blind-state.
Blind-state: In this mode you are blinded by a bright flash. This will affect your normal commands like ‘look’ and help until the blindness wears off after a certain time.
Timers are handled by persistent delays on the button. These are examples of evennia.utils.utils.delay calls that wait a certain time before calling a method - such as when closing the lid and un-blinding a character.
-
class
evennia.contrib.tutorials.red_button.red_button.
CmdPushLidClosed
(**kwargs)[source]¶ Bases:
evennia.commands.command.Command
Push the red button (lid closed)
- Usage:
push button
-
key
= 'push button'¶
-
aliases
= ['press', 'push', 'press button']¶
-
locks
= 'cmd:all()'¶
-
func
()[source]¶ This is the version of push used when the lid is closed.
An alternative would be to make a ‘push’ command in a default cmdset that is always available on the button and then use if-statements to check if the lid is open or closed.
-
help_category
= 'general'¶
-
lock_storage
= 'cmd:all()'¶
-
search_index_entry
= {'aliases': 'press push press button', 'category': 'general', 'key': 'push button', 'no_prefix': ' press push press button', 'tags': '', 'text': '\n Push the red button (lid closed)\n\n Usage:\n push button\n\n '}¶
-
class
evennia.contrib.tutorials.red_button.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.
-
key
= 'nudge lid'¶
-
aliases
= ['nudge']¶
-
locks
= 'cmd:all()'¶
-
help_category
= 'general'¶
-
lock_storage
= 'cmd:all()'¶
-
search_index_entry
= {'aliases': 'nudge', 'category': 'general', 'key': 'nudge lid', 'no_prefix': ' nudge', '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 push the lid of the button away.\n\n "}¶
-
class
evennia.contrib.tutorials.red_button.red_button.
CmdSmashGlass
(**kwargs)[source]¶ Bases:
evennia.commands.command.Command
Smash the protective glass.
- Usage:
smash glass
Try to smash the glass of the button.
-
key
= 'smash glass'¶
-
aliases
= ['smash lid', 'smash', 'break lid']¶
-
locks
= 'cmd:all()'¶
-
help_category
= 'general'¶
-
lock_storage
= 'cmd:all()'¶
-
search_index_entry
= {'aliases': 'smash lid smash break lid', 'category': 'general', 'key': 'smash glass', 'no_prefix': ' smash lid smash break lid', 'tags': '', 'text': '\n Smash the protective glass.\n\n Usage:\n smash glass\n\n Try to smash the glass of the button.\n\n '}¶
-
class
evennia.contrib.tutorials.red_button.red_button.
CmdOpenLid
(**kwargs)[source]¶ Bases:
evennia.commands.command.Command
open lid
- Usage:
open lid
-
key
= 'open lid'¶
-
aliases
= ['open button']¶
-
locks
= 'cmd:all()'¶
-
help_category
= 'general'¶
-
lock_storage
= 'cmd:all()'¶
-
search_index_entry
= {'aliases': 'open button', 'category': 'general', 'key': 'open lid', 'no_prefix': ' open button', 'tags': '', 'text': '\n open lid\n\n Usage:\n open lid\n\n '}¶
-
class
evennia.contrib.tutorials.red_button.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).
Note that this is given with a key_mergetype set. This is set up so that the cmdset with merge with Union merge type except if the other cmdset to merge with is LidOpenCmdSet, in which case it will Replace that. So these two cmdsets will be mutually exclusive.
-
key
= 'LidClosedCmdSet'¶
-
path
= 'evennia.contrib.tutorials.red_button.red_button.LidClosedCmdSet'¶
-
-
class
evennia.contrib.tutorials.red_button.red_button.
CmdPushLidOpen
(**kwargs)[source]¶ Bases:
evennia.commands.command.Command
Push the red button
- Usage:
push button
-
key
= 'push button'¶
-
aliases
= ['press', 'push', 'press button']¶
-
locks
= 'cmd:all()'¶
-
func
(**kwargs)¶ This is the actual executing part of the command. It is called directly after self.parse(). See the docstring of this module for which object properties are available (beyond those set in self.parse())
-
help_category
= 'general'¶
-
lock_storage
= 'cmd:all()'¶
-
search_index_entry
= {'aliases': 'press push press button', 'category': 'general', 'key': 'push button', 'no_prefix': ' press push press button', 'tags': '', 'text': '\n Push the red button\n\n Usage:\n push button\n\n '}¶
-
class
evennia.contrib.tutorials.red_button.red_button.
CmdCloseLid
(**kwargs)[source]¶ Bases:
evennia.commands.command.Command
Close the lid
- Usage:
close lid
Closes the lid of the red button.
-
key
= 'close lid'¶
-
aliases
= ['close']¶
-
locks
= 'cmd:all()'¶
-
help_category
= 'general'¶
-
lock_storage
= 'cmd:all()'¶
-
search_index_entry
= {'aliases': 'close', 'category': 'general', 'key': 'close lid', 'no_prefix': ' close', '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.tutorials.red_button.red_button.
LidOpenCmdSet
(cmdsetobj=None, key=None)[source]¶ Bases:
evennia.commands.cmdset.CmdSet
This is the opposite of the Closed cmdset.
Note that this is given with a key_mergetype set. This is set up so that the cmdset with merge with Union merge type except if the other cmdset to merge with is LidClosedCmdSet, in which case it will Replace that. So these two cmdsets will be mutually exclusive.
-
key
= 'LidOpenCmdSet'¶
-
path
= 'evennia.contrib.tutorials.red_button.red_button.LidOpenCmdSet'¶
-
-
class
evennia.contrib.tutorials.red_button.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.
-
key
= 'look'¶
-
aliases
= ['ex', 'l', 'get', 'feel', 'listen', 'examine']¶
-
locks
= 'cmd:all()'¶
-
help_category
= 'general'¶
-
lock_storage
= 'cmd:all()'¶
-
search_index_entry
= {'aliases': 'ex l get feel listen examine', 'category': 'general', 'key': 'look', 'no_prefix': ' ex l get feel listen examine', '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.tutorials.red_button.red_button.
CmdBlindHelp
(**kwargs)[source]¶ Bases:
evennia.commands.command.Command
Help function while in the blinded state
- Usage:
help
-
key
= 'help'¶
-
aliases
= ['h']¶
-
locks
= 'cmd:all()'¶
-
func
()[source]¶ Just give a message while blinded. We could have added this to the CmdBlindLook command too if we wanted to keep things more compact.
-
help_category
= 'general'¶
-
lock_storage
= 'cmd:all()'¶
-
search_index_entry
= {'aliases': 'h', 'category': 'general', 'key': 'help', 'no_prefix': ' h', 'tags': '', 'text': '\n Help function while in the blinded state\n\n Usage:\n help\n\n '}¶
-
class
evennia.contrib.tutorials.red_button.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.
Since this has mergetype Replace it will completely remove the commands of all other cmdsets while active. To allow some limited interaction (pose/say) we import those default commands and add them too.
We also disable all exit-commands generated by exits and object-interactions while blinded by setting no_exits and no_objs flags on the cmdset. This is to avoid the player walking off or interfering with other objects while blinded. Account-level commands however (channel messaging etc) will not be affected by the blinding.
-
key
= 'BlindCmdSet'¶
-
mergetype
= 'Replace'¶
-
no_exits
= True¶
-
no_objs
= True¶
-
path
= 'evennia.contrib.tutorials.red_button.red_button.BlindCmdSet'¶
-
-
class
evennia.contrib.tutorials.red_button.red_button.
RedButton
(*args, **kwargs)[source]¶ Bases:
evennia.objects.objects.DefaultObject
This class describes an evil red button. It will blink invitingly and temporarily blind whomever presses it.
The button can take a few optional attributes controlling how things will be displayed in its various states. This is a useful way to give builders the option to customize a complex object from in-game. Actual return messages to event-actions are (in this example) left with each command, but one could also imagine having those handled via Attributes as well, if one wanted a completely in-game customizable button without needing to tweak command classes.
Attributes: - desc_closed_lid: This is the description to show of the button
when the lid is closed.
desc_open_lid”: Shown when the lid is open
auto_close_msg: Message to show when lid auto-closes
desc_add_lamp_broken: Extra desc-line added after normal desc when lamp is broken.
blink_msg: A list of strings to randomly choose from when the lamp blinks.
Notes: The button starts with lid closed. To set the initial description, you can either set desc after creating it or pass a desc attribute when creating it, such as button = create_object(RedButton, …, attributes=[(‘desc’, ‘my desc’)]).
-
desc_closed_lid
= 'This is a large red button, inviting yet evil-looking. A closed glass lid protects it.'¶
-
desc_open_lid
= 'This is a large red button, inviting yet evil-looking. Its glass cover is open and the button exposed.'¶
-
auto_close_msg
= "The button's glass lid silently slides back in place."¶
-
lamp_breaks_msg
= 'The lamp flickers, the button going dark.'¶
-
desc_add_lamp_broken
= '\nThe big red button has stopped blinking for the time being.'¶
-
blink_msgs
= ['The red button flashes briefly.', 'The red button blinks invitingly.', 'The red button flashes. You know you wanna push it!']¶
-
to_closed_state
(msg=None)[source]¶ Switches the button to having its lid closed.
- Parameters
msg (str, optional) – If given, display a message to the room
lid closes. (when) –
This will first try to get the Attribute (self.db.desc_closed_lid) in case it was set by a builder and if that was None, it will fall back to self.desc_closed_lid, the default description (note that lack of .db).
-
to_open_state
()[source]¶ Switches the button to having its lid open. This also starts a timer that will eventually close it again.
-
blind_target
(caller)[source]¶ Someone was foolish enough to press the button! Blind them temporarily.
- Parameters
caller (Object) – The one to be blinded.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶ Bases:
evennia.objects.objects.DefaultObject.MultipleObjectsReturned
-
path
= 'evennia.contrib.tutorials.red_button.red_button.RedButton'¶
-
typename
= 'RedButton'¶