Comments (5)
All world objects have an addTrait
method. So you would first create your "lib.traits.attackable" object with the suitable methods and properties, and add it to some other object.
addTrait( ...WorldObject ) ⇒ Integer
Adds traits to the object and returns the number of traits. Traits are what makes the object inherit properties and methods.
Warning: it doesn't prevent from adding an already existing trait. Maybe it should, otherwise the object gets broken, with a 'duplicate parent'.
from room.js.
By the way, maybe your question is how to create a new trait in the first place. One possible way among others:
lib.root.new('lib.traits.attackable') // Spawn new object
lib.traits.attackable.rmTrait(lib.root) // Detach from root, for the trait to be standalone
// Then add properties, functions and verbs to lib.traits.attackable
...
// Then add this trait to some object, e.g. here to the baker NPC in the standard demo
items.baker.addTrait(lib.traits.attackable)
This should be what you asked for — Let me know if I can close the question.
from room.js.
if i add a new folder/files under the traits folder of a world, where do i get it to recognize that trait? can you point me to where it reads in all the "built in" traits? thanks!
i guess my main question is can i add a trait by just adding files/folders in the right spot?
something like:
world/lib/traits/attackable/attackable.json and the respective verbs/listener functions
thanks for the response!
from room.js.
As I said, the above is one possible way. I tend to favor coding from within the game (e.g. toggling to EVAL mode with TAB), since it's a pretty neat feature (and less error-prone, in my opinion).
But yes, you can also work directly with files directly on disk, if that's your preference. And something such as world/lib/traits/attackable/attackable.json
, provided it has the correct structure, will just map to lib.traits.attackable
. There's a one-to-one mapping between folders on disk and Javascript objects available in-game.
There's nothing as "built-in" traits, though, so no "right spot", strictly speaking — You are free to organize your object hierarchy as you wish (*). Traits are just other objects you use for inheritance. You could as well decide to create combat.classes.attackable
(i.e. on disk, world/combat/classes/attackable/attackable.json
) and use that as a trait. You organize your world code as you wish.
EDIT: (*) In the standard demo, lib.npc and lib.npcs.seller are such examples of objects used as traits (in items.baker, items.butcher, items.mouse, etc.) but not located in lib.traits.
from room.js.
Sounds good to me, thanks for the clarification and feedback!
from room.js.
Related Issues (20)
- Add more unit test coverage
- Create black-box functional tests HOT 1
- Give more control over parsing to the world implementation rather than hard-coding it in the server HOT 2
- Include a proper changelog for this release
- Add a contributors document to give proper credit
- Create an upgrade script to upgrade 3.x worlds to 4.0 worlds
- Add customizable server login messages and help messages
- Node 8.0.0 can't run the tests
- Investigate performance
- Add right prompt
- External text files on objects HOT 2
- Robustness issue in get-xxx and/or save-xxx socket commands
- Make login/authentication (a bit) more state-automata friendly
- Robustness issue in responses to 'request-input' events
- Array types do not update? HOT 2
- Parser: Incorrect ordering of exact and partial matches
- An in-range update of hashids is breaking the build 🚨 HOT 3
- http://roomjs.dose.ninja/ don't work
- An in-range update of socket.io is breaking the build 🚨 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from room.js.