-
Translator: Can this be easily changed? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If your use case is to print the full description when entering a room, could use the {
id: 'roomid',
name: 'Room Name',
desc: `Long description of the room`,
onEnter: () => {
const room = getRoom('roomid')
if(room.visits > 1) {
println(room.desc)
}
}
} On the first visit, the description will be printed by the engine. On successive visits, the description will be printed by this In order to apply it to each room, you would have to copy this to each room's |
Beta Was this translation helpful? Give feedback.
-
Hi, thank you for your question and very glad you like the engine! There are a number of ways to tackle this. @dthigpen's recommendation above is one way. The upside to this approach is that it doesn't change anything about how the engine works, which is a less brittle approach (because if the engine changed, your adaption might break). The downside is that it isn't very DRY (as in "don't repeat yourself"). I should note here I'm referring to the idea of updating each room manually to do this. The suggestion of applying this change programmatically would certainly DRY it up. Another approach which would be more DRY but also more brittle would be to override the const defaultEnterRoom = enterRoom;
enterRoom = (id) => {
defaultEnterRoom(id);
const room = getRoom(id);
if(room.visits > 1) {
println(room.desc)
}
}; Another way which is more brittle but also dead simple would be to simply change the // if (room.visits === 0) {
println(room.desc);
// } |
Beta Was this translation helpful? Give feedback.
Hi, thank you for your question and very glad you like the engine!
There are a number of ways to tackle this. @dthigpen's recommendation above is one way. The upside to this approach is that it doesn't change anything about how the engine works, which is a less brittle approach (because if the engine changed, your adaption might break). The downside is that it isn't very DRY (as in "don't repeat yourself"). I should note here I'm referring to the idea of updating each room manually to do this. The suggestion of applying this change programmatically would certainly DRY it up.
Another approach which would be more DRY but also more brittle would be to override the
enterRoom
command. You woul…