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.DefaultScriptThis 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.
-
path= 'evennia.contrib.tutorial_examples.bodyfunctions.BodyFunctions'¶
-
typename= 'BodyFunctions'¶
-
exception
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.
Bases:
evennia.commands.cmdset.CmdSetThis is the cmdset added to the account when the button is pushed.
Setup the blind cmdset
Bases:
evennia.commands.command.CommandHelp function while in the blinded state
- Usage:
help
Give a message.
Bases:
evennia.commands.command.CommandLooking around in darkness
- Usage:
look <obj>
… not that there’s much to see in the dark.
This replaces all the senses when blinded.
Bases:
evennia.commands.command.Commandclose the lid
- Usage:
close lid
Closes the lid of the red button.
Close the lid
Bases:
evennia.commands.command.CommandTry to nudge the button’s lid
- Usage:
nudge lid
This command will have you try to push the lid of the button away.
nudge the lid. Random chance of success to open it.
Bases:
evennia.commands.command.Commandopen lid
- Usage:
open lid
simply call the right function.
Bases:
evennia.commands.command.CommandPush the red button
- Usage:
push button
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.
Bases:
evennia.commands.command.Commandsmash glass
- Usage:
smash glass
Try to smash the glass of the button.
The lid won’t open, but there is a small chance of causing the lamp to break.
Bases:
evennia.commands.cmdset.CmdSetThe 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().
Init the cmdset
Bases:
evennia.commands.cmdset.CmdSetA 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).
Populates the cmdset when it is instantiated.
Bases:
evennia.commands.cmdset.CmdSetThis is the opposite of the Closed cmdset.
setup the cmdset (just one command)
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!
Bases:
evennia.objects.objects.DefaultObjectThis 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
Bases:
evennia.objects.objects.DoesNotExist
Bases:
evennia.objects.objects.MultipleObjectsReturned
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.
Breaks the lamp in the button, stopping it from blinking.
- Parameters
feedback (bool) – Show a message about breaking the lamp.
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.
Opens the glass lid and start the timer so it will soon close again.
Someone was foolish enough to press the button!
- Parameters
pobject (Object) – The person pressing the button
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.
Bases:
evennia.scripts.scripts.DefaultScriptThis 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.
Bases:
evennia.scripts.scripts.DoesNotExist
Bases:
evennia.scripts.scripts.MultipleObjectsReturned
We set up the script here.
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.
It’s important that we clear out that blinded cmdset when we are done!
Bases:
evennia.scripts.scripts.DefaultScriptThis timed script lets the button flash at regular intervals.
Bases:
evennia.scripts.scripts.DoesNotExist
Bases:
evennia.scripts.scripts.MultipleObjectsReturned
Called every self.interval seconds. Makes the lamp in the button blink.
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).
Button will keep blinking unless it is broken.
Bases:
evennia.scripts.scripts.DefaultScriptThis 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.
Bases:
evennia.scripts.scripts.DoesNotExist
Bases:
evennia.scripts.scripts.MultipleObjectsReturned
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.
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).
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.
Bases:
evennia.scripts.scripts.DefaultScriptThis 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)
Bases:
evennia.scripts.scripts.DoesNotExist
Bases:
evennia.scripts.scripts.MultipleObjectsReturned
Called when script first created.
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.
When the script stops we must make sure to clean up after us.
The script is only valid while the lid is closed. self.obj is the red_button on which this script is defined.
Bases:
evennia.scripts.scripts.DefaultScriptThis 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.
Bases:
evennia.scripts.scripts.DoesNotExist
Bases:
evennia.scripts.scripts.MultipleObjectsReturned
When this is called, reset the functionality of the button.
Sets things up.
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)
Bases:
evennia.scripts.scripts.DefaultScriptThis manages the cmdset for the “open” button state. This will add the RedButtonOpen
Bases:
evennia.scripts.scripts.DoesNotExist
Bases:
evennia.scripts.scripts.MultipleObjectsReturned
Called when script first created.
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.
When the script stops (like if the lid is closed again) we must make sure to clean up after us.
The script is only valid while the lid is open. self.obj is the red_button on which this script is defined.
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
-