MZ Cannot log function before while(true)

So i've ran into a problem right now. I want to log the MyMethod method to the console, but somehow the result is empty and it happens when i have a while(true) loop right after, but i dont know why.

Code:
class MyClass {
  public static command;

  private static MyMethod() {
    console.log("test1");
    console.log("test2");
    console.log("test3");
  }

  public static DoSomething() {
    this.command = this.MyMethod;

    console.log(this.ShowTextAdapter);
    console.log(this.ShowTextAdapter);
    console.log(this.ShowTextAdapter);
    console.log(this.ShowTextAdapter);
    console.log(this.ShowTextAdapter);

    while (true) {}
  }
}
while (true) {} is a fairly reliable way to freeze the current thread and not allow JavaScript to do anything, which apparently includes preventing console logs from working. The solution is to remove the while (true) {} statement, it should fix it right up 😉

Why did you want to include it in the first place?
while (true) {} is a fairly reliable way to freeze the current thread and not allow JavaScript to do anything, which apparently includes preventing console logs from working. The solution is to remove the while (true) {} statement, it should fix it right up 😉

Why did you want to include it in the first place?
I need the while true later to update some stuff, so i can't just remove it. Is there a way to make the logs working again without removing the loop?
I need the while true later to update some stuff, so i can't just remove it. Is there a way to make the logs working again without removing the loop?
There's no way to make anything work while there's a loop that runs forever.
I'm assuming you mean you'll put some code inside it later? Then for now comment it out until it's actually needed, or replace it with while(true){break;} if you really need to see it there.
So i've ran into a problem right now. I want to log the MyMethod method to the console, but somehow the result is empty and it happens when i have a while(true) loop right after, but i dont know why.

Code:
class MyClass {
  public static command;

  private static MyMethod() {
    console.log("test1");
    console.log("test2");
    console.log("test3");
  }

  public static DoSomething() {
    this.command = this.MyMethod;

    console.log(this.ShowTextAdapter);
    console.log(this.ShowTextAdapter);
    console.log(this.ShowTextAdapter);
    console.log(this.ShowTextAdapter);
    console.log(this.ShowTextAdapter);

    while (true) {}
  }
}
This looks like a strange frankenstein langauge between Java and Javascript (they are UNRELATED langauges). That aside, the only thing this does is define a new class of objects. It does nothing because it doesn't tell the game to create an instance of MyClass and give it any commands.

What you want to do is to create a new instance of MyClass and store it into a variable. Then, you call its function. Basically you add that to the end of your code. That said I don't think my code will necessarily work as I've never seen public or static declrations used for Javascript, but I've seen it used for Java.

Code:
var $myObject = new MyClass();
$myObject.DoSomething();

EDIT: What I would have done instead is something along the lines of this. If you needed myClass to be a static class where you do not need multiple copies of, it would look like this. The following code is 100% Javascript and will work as a .js file installed as a plugin.

Code:
//Create a new object named myClass
var myClass = {};

//define a method for this class
myClass.myMethod = function() {

    console.log("test1");
    console.log("test2");
    console.log("test3");

 }

//define another method for this class
myClass.doSomething = function() {

    console.log("Do Something");

  }

//execute the methods
myClass.doSomething();
myClass.myMethod();
I've never seen public or static declrations used for Javascript
MV doesn't use it, but the static part is valid syntax


I don't see anything that supports the public and private keywords, though.
MV doesn't use it, but the static part is valid syntax


I don't see anything that supports the public and private keywords, though.
That is because i am using Typescript. Typescript supports public and private keywords.
Anyways, i found out, that i can't solve my problem the initial way i thought, but i've got another solution for it. Thank you for help.

Original thread: https://forums.rpgmakerweb.com/threads/cannot-log-function-before-while-true.169817/