[SOLVED] A Script That Can Insert Your Windows Username

So I'm sure you all know about this trend in games where they break the fourth wall by calling you by your computer username. However, I haven't found any plugins or anything for it in MV!

That being said, I was wondering if someone could introduce me to a script that could get the name of the Windows account that you're logged into and assign that to an actor name or variable... If it's even possible, that is.

I found a thread that asked the same exact question for VX Ace if you need any clarification: http://www.rpgmakercentral.com/topic/27558-looking-for-a-script-that/

If anyone could help, it would be much appreciated.
Mmm... If I understood correclty, you want to catch the windows user name and maybe save it in a variable.
You can make a test saving the os name in a variable like this, using the script command in the event editor:

Code:
var os = require('os')
$gameVariables.setValue(1, os.hostname())

Using this script, you will save the host name in the variable of id 1.
If you want to change the variable id, you have only to change the "1" in the code.
Thanks for the quick response!

I made sure to do everything as instructed, but upon trying that, I ended up with an error that I have attached.
It's unlikely that you'd be able to reference data from programs outside of the game engine, especially for an end user.

https://stackoverflow.com/questions...lients-machine-computer-name-from-the-browser
Yeah, I thought so, and I was actually looking at that very thread before starting this one.

Thing was that I had my hopes up when I saw that it was possible in VX Ace. However, I understand that MV and VX Ace use two different programming languages, and that Javascript can't do certain things that Ruby could (and visa versa).

Still though, I wanted to see if there was any way whatsoever that I could to it before giving up.
The error looks related to a missing image inside the img/system folder. Not an error on the hostname itself.
The code I used is from Node Js, if you try to push something similar in the console (F8):

Code:
var os = require('os')
os.hostname()

EDIT:
I was just thinking, you can try this, too:

Code:
var os = require('os')
os.userInfo().username

You notice that the hostname is actually catched up.
What's the image you're trying load?
So it turns out that the whole image fiasco was an issue with one of the plugins that I had.

Unfortunately when trying the first script on a clean slate, I ended up just getting "DESKTOP-XXXXXX" as the "name."

The "os.userInfo().username" code snippet looked the most promising, however that script returned with an "TypeError: Undefined is not a function" message.
Mmm... It's probably related to the fact that the Node JS version used in MV is an old version.
You can maybe solve the problem using this ponyfill, look here:


Install using npm in your js folder, and then use this code:
Code:
var userInfo = require('./js/node_modules/user-info/index.js')
userInfo().username
You mean you can somehow install it TO your js folder?

(My apologies. I'm a noob at this sort of stuff.)
In a little sidenote, i never thought RMMV carried a instance of Node inside it (yes, i know the engine is powered by a CEF executable, but i didnt knew it have a node instance too)
@Mangozebra The js folder of your project.
Okay, it worked! (Also I figured out the problem with the plugin.)

Thank you so much for your help, @Gamefall Team!
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/solved-a-script-that-can-insert-your-windows-username.87772/