New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 console.log
not working in player.js
#69
Comments
Hey @jakehamilton! Thanks for your detailed issue, I agree that something like this is needed (as other people have asked in the past: #41). I'm going to take the time to think how this could be best implemented. I could inject
Any suggestion is welcome, and thanks again. |
@olistic thanks for the quick reply! So far I'm thinking something along the lines of
A separate logs section doesn't look too bad:
Perhaps a little theming within the context of the world would help it fit in better:
|
Just a thought to keep the logging "in character" with the game, as if the warrior was carrying a journal and taking notes in it to aid progress. |
Another option in those same lines (but that doesn't interfere with the Example: class Player {
playTurn(warrior, journal) {
if (warrior.feel().isEmpty()) {
journal.write("I'm not sure if I should work here...");
warrior.walk();
}
}
} I'm not sure it's the best solution though. |
@benfletcher logging to a separate file would get the job done. I do think that would separate the logs from their isolated turn though. Were I to want to log out some data and double check it by looking at the level print out for a given turn, I would need both my terminal and a separate file open. @olistic I think it could make sense to separate the |
@olistic (also probably @jakehamilton @benfletcher for interest) I went ahead and made an example implementation of this because I wanted to see if I could check the enemy type ahead of me with I exposed two functions to the Player instance, // PlayerLoader.createPlayer()
// See other implementations in 'Logger.js', 'ui/printDebugMessage.js', and 'ui/printPlay.js'
player.say = (...messages) => Logger.log(messages.length > 1 ? messages : messages[0]);
player.debug = (...args) => console.log(util.inspect(args, {showHidden: false, depth: null, colors: true})); These are the results of calling this.debug(warrior.feel())
this.say(warrior.feel().toJSON())
The code probably isn't very good, it's a LARGE project and I did the best I could with what I could make out and infer from the stuff you'd already written. If you want to take a look, it's here: Code Diff: |
Just noticed there's a bug with the console styling switching between bold and not. I'll fix that later 😂 |
I found using the debugger super helpful. It's easiest with a local npm install:
and then add an index.js as follows 'use strict';
require('@warriorjs/cli/bin/warriorjs'); now you can debug with:
|
@pajtai Ahhh, I didn't think of that. I thought about running with the |
@jakehamilton @benfletcher @GavinRay97 @pajtai I decided to implement a basic solution for this issue in #102. Please check it out (and maybe try it), any feedback is appreciated. |
WarriorJS v0.3.0 includes a |
warriorjs v3.0.0 is live on npm but doesn't seem to enable this |
@cavejay you’re probably installing the old package, |
yup. that was it. Was trying to figure out why my readme's weren't markdown as well. This would explain it |
Environment
Steps to reproduce
npm i -g warriorjs
warriorjs
(follow default config)Player.js
and add aconsole.log('hello')
statement in theplayTurn
methodplayTurn () { console.log('Hello World'); }
warriorjs
(select your character to run)Expected Behavior
All
console
statements should be displayed in the output (or at least logged to a file).Actual Behavior
No
console
statements display.Additional Notes
So far I think the issue comes from running in a new vm context. That call happens here: https://github.com/olistic/warriorjs/blob/master/packages/warriorjs-core/src/PlayerLoader.js#L23
And finally, this is a really cool project. Thanks to everyone for the great work so far!
The text was updated successfully, but these errors were encountered: