Evennia Coding Challenges #2295
Replies: 2 comments 5 replies
-
Torch Challenge - 1/5 DifficultyChallenge SummaryMake a torch typeclass that has a fuel attribute. Add to it an ignite method which causes a message to echo to the room and a ticker to begin eating away at the fuel until the torch dies. Each time the ticker executes the specified method, check that there is remaining fuel and echo a message to the room. Once dead, destroy the torch. Create a new command that calls upon the torch's ignite method, getting the process started. Torch ObjectIn def at_object_creation(self):Within this method add your fuel attribute, as well as a rate for how much fuel will be consumed per tick. def ignite(self, igniter):Create an Send a message to the igniting character that they've lit the torch. You should also send a message to all of the room's contents, using the Add a tickerhandler and set the seconds to the frequency which you wish the torch to burn at. This is also the frequency that will echo the messages to the room, letting characters in the room know that the torch is still burning. In the tickerhandler, also add the method you wish to call per tick. I used def on_burn_tick(self):Start out by getting the attributes for the total fuel value and fuel burn rate from the torch and assigning those to variables. Now it's time to do some conditional checks. We need to know if the fuel has enough left to burn another tick, so the first thing we want to check for is if the fuel is less than or equal zero. If that's the case, we should call upon Now that we know the torch has enough fuel to burn, since it passed our death check, we can echo a message to the room via We also need to set the torch's fuel attribute to
def death(self):Now that the torch is dead you should remove the Next, you need to echo a death message for the torch to the room, letting players know that it's finished. Finally, use Ignite CommandYou have the logic written for what happens with the torch, but you need a way to initiate this logic. This can be done via a command. Create a new command in your def parse(self):The parsing method of a command is used to determine the validity of the arguments passed to the command and to exit the command prematurely if a condition is not met. Commands have a built-in property on them that holds the object (usually a character) that called the command. This is Commands also have another property that tracks the arguments passed to it, this is In the parse method, we need to check to see if there are any arguments at all. If there are no arguments stored in
If Generally you will have extra whitespace on the leftside of an argument, so you want to clean that up with Now that you've got a clean string, it's time to search for the object that best represents the string passed to the command. In this case, we are looking to search for a torch. Out in the wilds of your code, you may have to use a utility like Now that you have your torch object stored in a variable, I highly suggest checking it to make sure that it is the proper typeclass. This will prevent unexpected behavior by having characters trying to ignite things you don't want ignited! There are several ways to check if an object is the proper type of object you are looking for; tags are one example of something I use quite often. In this case, we know that we have a custom typeclass of Torch and so we can use that to check. For this check, we will utilize If the object isn't the Torch typeclass, send an error message to the caller and raise InterruptCommand. Else, if it is the Torch typeclass, assign the object to def func(self):We have all of our parsing out of the way and we are certain that we have an object stored and that it is of the proper typeclass. Now it's time to execute our command's logic. In this case, the logic is simply to call the ignite method of the torch object. Additional ThoughtsViola! There you have it. A functioning torch that can be ignited, echos for a bit to the room, and then dies. There's a few things that can be done to beef up the torch from here. You should really try to make this challenge your own and wow the rest of us with your fantastic torch/lantern/flashlight, whatever it is you want to do! For me, I wanted to track the location of the torch. Is it in the hands of a player or is it lying on the floor of a room? If a player is holding it, they should see a different output from the torch than the other folk in the room. Try tracking the torch's Something else you might want to do, that I have yet to implement, is have your room object track lighting and get your torch to interact with the lighting attribute of the room. See if you can make the room lighter or darker. There are a multitude of ways to handle this and the lighting attribute may not even need to be placed on the room itself. See if you can take it even further and change how players can interact with the room, such as the look command, based on the lighting. |
Beta Was this translation helpful? Give feedback.
-
Here's a coding challenge, though I likely won't write it in as detailed a manner as Kovitikus did. "Make A Cat You Can Pet" Challenge - 1/10 DifficultyChallenge Summary Challenge Process |
Beta Was this translation helpful? Give feedback.
-
ATTENTION!
Only post a new message directly to this main thread if it is a challenge. To respond to a challenge, there are separate reply boxes below each main post that will create a sub-thread. Place any questions, suggestions, or ideas regarding that specific challenge within the sub-thread.
Introduction
The purpose of this thread is to gather ideas for coding challenges that the community can tackle, specifically those new to the engine.
Challenges are unlike tutorials. They aren't step-by-step and laid out, holding your hand. They are somewhere in-between a tutorial and the cold dark empty void where you're left to your own devices. If you are new to Evennia, these challenges will help teach you how to navigate the Evennia API and documentation. They should also give you the confidence to solve problems on your own. These two skills may be the most critical things you can master!
Do not cheat! By cheating, I mean looking at another person's solution before you attempt to carve your own path. You will only hurt yourself! The point of these challenges is to think, and copying another person's solution requires no thinking.
Ask questions! Flood this thread with questions, they are not considered cheating. But, try your best to solve your own problem before asking for help. I will fully admit that I wouldn't have gotten anywhere with Evennia if I didn't have helpful folk answering my questions, but I also had to find the right balance between being handed an answer and seeking out my own.
There are a lot of resources already written for Evennia and my hope is that these challenges will help point you in the right direction when it comes to utilizing these resources.
I would also like to ask that you try to keep your questions and answers contained within this thread. It's not wrong to ask questions in live chat, such as Discord or IRC, but those questions and answers will get lost to history. It's best that we keep as much information contained herein as possible, to avoid having the same questions asked multiple times.
Challenge Layout
A challenge should be laid out in the following manner, as to best facilitate conveying the idea and maximizing resource references. Be certain to include any tidbits that might not be explained in other sections of Evennia; little tips or quirks when managing your code's logic that is critical to its function.
##
for main titles and####
for method sections.Please post your solutions in the sub-thread of the challenge post; even if you are the author of the challenge. This will help keep the solution slightly detached from the main challenge post and make it less likely for the reader to ruin their challenge by clicking on the solution prematurely!
The posted solution should be "hidden". Anybody taking the coding challenge should not check the solution until they feel they've completed the challenge to the best of their ability. Coders can then check their results against the posted solution to compare their outcome to others.
Use this HTML code to post a solution.
Click here for the solution!
Here is the solution I developed for the challenge.Be sure to post all of your code related to the challenge
and mark where it is placed in the project, to track organization.
Beta Was this translation helpful? Give feedback.
All reactions