Loading Python code into an NPC to make a programming mini-game.

321 views
Skip to first unread message

Ashlan

unread,
Mar 31, 2017, 3:19:54 AM3/31/17
to Evennia
I've been trying to come up with an asynchronous aspect for my MUD and one thing I've always had on my projects list is a programming game where people program robots/monsters that fight each other.

So in one possible version of this, NPCs are created and left on the map and they react to other NPCs (maybe also players) based upon Python code / a form of psuedo-code that was uploaded into them.

The basic concepts like how to get NPCs to do things, how to make new skills and rooms and objects, I have a fairly good grasp of these things within Evennia by now.  But how to load up large amounts of code and have the game execute them within a context? This seems like a step higher in terms of difficulty.

I imagine I'd want to look into Evennia's editor to help load the code into the NPC object as some kind of reference, but after that I'm not completely sure how to do it.  I'd rather not write an entire Python compiler and I know that there's a @py function within the game, is there perhaps some way to easily write my own functions (perhaps with scripts), have them maybe compiled with something similar to the @py function and then they'd go from there? Or is there another way this might be done?

Thanks guys :)

Tim Ashley Jenkins

unread,
Mar 31, 2017, 3:32:44 AM3/31/17
to Evennia
Sounds like a security nightmare waiting to happen! If you let players execute arbitrary Python code, it's a trivial effort for them to tank your entire server, and there's no easy way to keep them from being able to do so. You're definitely better off coming up with a simple pseudocode language to use!

Ashlan

unread,
Mar 31, 2017, 6:09:33 AM3/31/17
to Evennia
Well, I was going to include an "energy level" where certain actions use up energy and once you're out, the code ends.  But I hadn't thought of a way to extend it to processes so in the end you're probably right! A pseudocode language does seem like it would be a better solution, although now I'm wondering how to effectively limit system resources...

Griatch Art

unread,
Mar 31, 2017, 10:46:31 AM3/31/17
to Evennia
Letting evennia execute code is simple, Python has its eval() and exec() functions to execute strings as code. See the @py command - your code would just take strings from some storage rather than direct input. That said, allowing your everyday players to execute arbitrary Python code on your server is a bad idea. As BattleJenkins mentioned, you are in for a world of hurt. Just don't do it, it's that simple.

One of our contributors, vincent, has an event system contrib in the works that allow Python coding in-game. But that's something intended for privileged users, not a standard game element for everyone that connects. So yeah, a simple pseudo-language is probably better for something like this.
.
Griatch

Vincent LE GOFF

unread,
Apr 1, 2017, 3:39:19 PM4/1/17
to eve...@googlegroups.com

I would agree on the pseudo-language solution.  Executing Python from Python is simple (there's no compiling in Python, at least, not the way C or other "static" languages use this) so it's just a matter of executing some Python keywords/functions.  But yeah, that would be dangerous if all your players could do the same thing.  The event system I'm working on is great for slightly altering the behavior of individual objects, like giving NPCs lines of dialogue, creating a simple (or not so simple) quest and have pieces of arbitrary Python code executed in different contexts.  But again, the potential for misuse is infinite, much like giving the @py command to all your players.


A simple pseudo-programming language sounds a better solution for you.  Also, I'd point out that, if you want all your NPCs to move randomly and attack each other, you might be better off creating a simple NPC typeclass and having a script/ticker moving them randomly and attacking one another.  If there's not a lot of variation, a pseudo-programming language sounds like an overkill to me.  Again, it really depends on what you want to do.  Keeping the end in mind, I guess simple softcode is what you're looking for.  It won't be that easy to create, but it won't pose the same risk as having players code in Python right into your game.


HTH,


Vincent

--
You received this message because you are subscribed to the Google Groups "Evennia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to evennia+u...@googlegroups.com.
To post to this group, send email to eve...@googlegroups.com.
Visit this group at https://groups.google.com/group/evennia.
To view this discussion on the web visit https://groups.google.com/d/msgid/evennia/67ce99e6-687e-4ea8-9670-2cd4e47ff295%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages