Get variables/actor name within manual text display?

Discussion in 'Learning Javascript' started by Badweather4cast, Aug 8, 2017.

  1. Badweather4cast

    Badweather4cast Master Eventer Veteran

    Messages:
    38
    Likes Received:
    34
    Location:
    Ansalon
    First Language:
    English
    Primarily Uses:
    RMVXA
    Hey all,

    Due to the type of project I am working on, the built-in text display function won't be either aesthetically or mechanically pleasing. It's taken some time, but eventually I did find the code to create text within a new window manually via script call:

    Code:
    var window = new Window_Base(x, y, width, height);
    window.drawText("Hello World", x, y, maxWidth, lineHeight, alignment);
    SceneManager._scene.addWindow(window);
    This works swimmingly, and I probably would have gotten it to work sooner if I'd actually known what I was doing. But, as I am currently uneducated in the ways of JavaScript, I've been unable to figure out how to draw the name of X actor within the text, or draw any variables at all. Of course, codes used in the built-in message windows (such as \N[X] or \V[X]) will not work here, as they are not defined. But I am unsure of what my plan is here, I don't know how to define these commands to get the response I'm looking for.

    If anyone can help me out, that would be awesome. I'm happy to provide more details if necessary, I realize I'm definitely missing something obvious.
     
    #1
  2. waynee95

    waynee95 Lunatic Coder Veteran

    Messages:
    640
    Likes Received:
    529
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    PHP:
    // Get the name of the actor with id 4
    var actorName $gameActors.actor(4).name();
    PHP:
    // Get the value of variable with id 42
    var value $gameVariables.value(42);
    PHP:
    // Draw the value of variable 42
    var value $gameVariables.value(42);
    window.drawText(valuexymaxWidth);
     
    #2
  3. Badweather4cast

    Badweather4cast Master Eventer Veteran

    Messages:
    38
    Likes Received:
    34
    Location:
    Ansalon
    First Language:
    English
    Primarily Uses:
    RMVXA
    @waynee95 Thanks, this definitely helps! I have one last question, however: For the actor's name in particular, after defining it, is there any way to make it appear within the "Hello World" of the drawText, or must that be done separately? (I'm sorry if that's a silly question, I'd just like to make sure I'm doing all this correctly.)
     
    #3
  4. waynee95

    waynee95 Lunatic Coder Veteran

    Messages:
    640
    Likes Received:
    529
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    Yes you can do that.

    PHP:
    // You can add any variables to the the text. Just make sure to have the text always between "" and variables are added with a +
    // Note: actorName refers to the code above, I was too lazy to type it again xD
    window.drawText("Hello World" actorName "Hello World."xymaxWidth);
     
    #4
    Badweather4cast likes this.
  5. Badweather4cast

    Badweather4cast Master Eventer Veteran

    Messages:
    38
    Likes Received:
    34
    Location:
    Ansalon
    First Language:
    English
    Primarily Uses:
    RMVXA
    #5
  6. jayray

    jayray Jay Ray Games and Art Design- Oklahoma City, OK Veteran

    Messages:
    133
    Likes Received:
    97
    Location:
    Oklahoma City, OK
    First Language:
    English
    Primarily Uses:
    RMMV
    now question... how to close that window once it's created?
     
    #6
    Badweather4cast likes this.
  7. jayray

    jayray Jay Ray Games and Art Design- Oklahoma City, OK Veteran

    Messages:
    133
    Likes Received:
    97
    Location:
    Oklahoma City, OK
    First Language:
    English
    Primarily Uses:
    RMMV
    I waited to bump this, does anyone know how to get a window to close once it's created in this way?
     
    #7
  8. GE_Peter

    GE_Peter Villager Member

    Messages:
    21
    Likes Received:
    2
    Location:
    Germany
    First Language:
    English
    Primarily Uses:
    RMMV
    window.close()

    It's a method in the Window_Base class.
     
    #8
    Badweather4cast likes this.

Share This Page