@groth said in What's So Hard About Ruby?:
I haven't tried it in Ares but I know in Evennia it's non-trivial to make something like a ball you can throw at people or a magic 8 ball or whatever.
I don't think doing that would be too difficult in Evennia either. I kinda structured this off some furniture code I wrote a long time ago on a pet project, but I'm really rusty with both Evennia and python at the moment so it's just a broad-strokes sketch and not meant to work out of the box and probably not the best way to do it!
from evennia import DefaultObject, CmdSet, default_cmds
import random
class EightBall(DefaultObject):
"A simple 8-ball"
def at_init(self):
self.ndb.fortunes = self.ndb.fortunes or ["1","2","3","4","5","6","7","8"]
def at_object_creation(self):
# add the commands associated with the 8-ball to each instance
self.cmdset.add("typeclasses.eightball.BallCmdSet", permanent=True)
def fortune(self):
# return a random selection from our fortunes. I don't think this return is an
# issue but if it were you might need to change how this is done.
selection = random.choice(self.ndb.fortunes)
return selection
class CmdShake(default_cmds.MuxCommand):
"""
Usage:
shake <object>
This command allows a character to read their fortune in an 8-ball.
"""
key = "shake"
arg_regex = r"\s.+" # require a space-separated argument, i.e. 'ball'
locks = "cmd:all()"
def parse(self):
self.target = self.args.strip()
def func(self):
caller = self.caller
target = caller.search(self.target)
if not target:
#yield an error if the target cannot be found
caller.msg(f"Can't find {self.target}.")
return
elif not isinstance(target, EightBall):
# ensure the command is being used on a valid target
caller.msg("Shaking that would be rude!")
return
else:
# provide a fortune to the caller
caller.location.msg_contents(f"{caller.key} shakes {target.key} and studies it closely.")
fortune = target.fortune()
caller.msg(f"Through {target.key}'s murky glass, you can read: {fortune}.")
return
class BallCmdSet(CmdSet):
"""
Base command set for 8-ball objects.
"""
key = "BallCmdSet"
def at_cmdset_creation(self):
self.add(CmdShake())
You could modify and complicate that in a host of ways, like having the main class have hundreds of fortunes and just pack a selection of 8 into each object (and be saved instead of being nbd), and so on, but it's a scaffold.
A huge challenge with an engine like Evennia, and from what faraday has been saying with Ares, is that a lot of its power comes from the fact that it has all kinds of hooks and tools distinct from the language it uses packed in everywhere. So even a simple idea ends up involving a lot of wrestling to learn how to get it to fit into the pattern of the engine, and that's really hard at first.
On the head subject of the thread, I think Ruby is pretty straightforward and no more difficult than Python or another alternative. My only experience with it was a mandatory semester of programming-for-non-programmers in college and I had no head for code but I suffered through it kinda well, and that's a point in the language's favor in a big way. The biggest hurdle to making any project a reality, imo, is bridging the gap from understanding the basics of a language (if you're approaching from a new-coder perspective) to understanding how to leverage whatever tools the engine you're using has to offer, and that's going to happen regardless of the language and regardless of the engine.