evennia.contrib.tutorial_examples.red_button_scripts

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.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)

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.

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.

at_stop()[source]

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

exception DoesNotExist

Bases: evennia.scripts.scripts.DefaultScript.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.DefaultScript.MultipleObjectsReturned

path = 'evennia.contrib.tutorial_examples.red_button_scripts.ClosedLidState'
typename = 'ClosedLidState'
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

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.

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.

at_stop()[source]

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

exception DoesNotExist

Bases: evennia.scripts.scripts.DefaultScript.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.DefaultScript.MultipleObjectsReturned

path = 'evennia.contrib.tutorial_examples.red_button_scripts.OpenLidState'
typename = 'OpenLidState'
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.

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!

exception DoesNotExist

Bases: evennia.scripts.scripts.DefaultScript.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.DefaultScript.MultipleObjectsReturned

path = 'evennia.contrib.tutorial_examples.red_button_scripts.BlindedState'
typename = 'BlindedState'
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.

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.

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.

exception DoesNotExist

Bases: evennia.scripts.scripts.DefaultScript.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.DefaultScript.MultipleObjectsReturned

path = 'evennia.contrib.tutorial_examples.red_button_scripts.CloseLidEvent'
typename = 'CloseLidEvent'
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.

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.

at_repeat()[source]

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

exception DoesNotExist

Bases: evennia.scripts.scripts.DefaultScript.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.DefaultScript.MultipleObjectsReturned

path = 'evennia.contrib.tutorial_examples.red_button_scripts.BlinkButtonEvent'
typename = 'BlinkButtonEvent'
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.

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)

at_repeat()[source]

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

exception DoesNotExist

Bases: evennia.scripts.scripts.DefaultScript.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.scripts.scripts.DefaultScript.MultipleObjectsReturned

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