How do i draw text ...
 
Notifications
Clear all

How do i draw text to the screen with a script

10 Posts
2 Users
0 Reactions
1,068 Views
0
Topic starter

 

I tried following the tutorials but when i copy paste the code in the plugins manager it just gives me errors

import { RPM } from "../path.js"

const pluginName = "ShowText";
const inject = RPM.Manager.Plugins.inject;

// Start code here

new Graphic.Text('mytext', { 
    x: 0, 
    y: 0, 
    w: 0, 
    h: 0, 
    align: Align.Left, 
    fontSize: Utils.defaultValue(Datas.Systems.dbOptions.v_tSize, Constants.DEFAULT_FONT_SIZE), 
    fontName: Utils.defaultValue(Datas.Systems.dbOptions.v_tFont, Constants.DEFAULT_FONT_NAME), 
    verticalAlign: AlignVertical.Center, 
    color: Utils.defaultValue(Datas.Systems.dbOptions.v_tcText, System.Color.WHITE), 
    bold: false, 
    italic: false, 
    backColor: Utils.defaultValue(Datas.Systems.dbOptions.v_tcBackground, null), 
    strokeColor: Utils.defaultValue(Datas.Systems.dbOptions.tOutline, false) ? Utils.defaultValue(Datas.Systems.dbOptions.v_tcOutline, null) : null
});

 

failed to load resource: net::ERR_FILE_NOT_FOUND

code.js:8 Uncaught ReferenceError: Graphic is not defined at code.js:8

Platform.js:144 Uncaught ReferenceError: Graphic is not defined at code.js:8

 

Am i misunderstanding?

4 Answers
0
Topic starter

I just realized i posted the wrong code, my mistake, here is what i tried:

 

import { RPM } from "../path.js";
import { Graphic } from "../core/index.js";

const pluginName = "ShowText";
const inject = RPM.Manager.Plugins.inject;

class MyTextPlugin {
  constructor() {
    this.textGraphic = new Graphic.Text("mytext", {
      x: 0,
      y: 0,
      w: 0,
      h: 0,
      align: Align.Left,
      fontSize: Utils.defaultValue(
        Datas.Systems.dbOptions.v_tSize,
        Constants.DEFAULT_FONT_SIZE
      ),
      fontName: Utils.defaultValue(
        Datas.Systems.dbOptions.v_tFont,
        Constants.DEFAULT_FONT_NAME
      ),
      verticalAlign: AlignVertical.Center,
      color: Utils.defaultValue(
        Datas.Systems.dbOptions.v_tcText,
        System.Color.WHITE
      ),
      bold: false,
      italic: false,
      backColor: Utils.defaultValue(
        Datas.Systems.dbOptions.v_tcBackground,
        null
      ),
      strokeColor: Utils.defaultValue(
        Datas.Systems.dbOptions.tOutline,
        false
      )
        ? Utils.defaultValue(Datas.Systems.dbOptions.v_tcOutline, null)
        : null,
    });
  }

  drawText() {
    this.textGraphic.draw();
  }
}

const myTextPluginInstance = new MyTextPlugin();

inject(Scene.Map.prototype, "drawHUD", function () {
  this._super.drawHUD.call(this);
  myTextPluginInstance.drawText();
});
0

Yes, you need to add RPM module before each module that come from RPG Paper Maker (or import each needed modules if you don't want to use RPM everytime). For example, use new RPM.Graphic.Text(...) for your error at line 8.

chay.hawk Topic starter 29/04/2023 10:17 pm

@wano Like this?

import { RPM } from "../path.js"
import { System } from "../../System/index.js";
import { Graphic } from "../../Graphic/index.js";

const pluginName = "ShowText";
const inject = RPM.Manager.Plugins.inject;

// Start code here

new RPM.Graphic.Text('mytext', {
x: 0,
y: 0,
w: 0,
h: 0,
align: Align.Left,
fontSize: Utils.defaultValue(Datas.Systems.dbOptions.v_tSize, Constants.DEFAULT_FONT_SIZE),
fontName: Utils.defaultValue(Datas.Systems.dbOptions.v_tFont, Constants.DEFAULT_FONT_NAME),
verticalAlign: AlignVertical.Center,
color: Utils.defaultValue(Datas.Systems.dbOptions.v_tcText, System.Color.WHITE),
bold: false,
italic: false,
backColor: Utils.defaultValue(Datas.Systems.dbOptions.v_tcBackground, null),
strokeColor: Utils.defaultValue(Datas.Systems.dbOptions.tOutline, false) ? Utils.defaultValue(Datas.Systems.dbOptions.v_tcOutline, null) : null
});

Wano Wano 30/04/2023 12:26 pm

Yeah but not only Graphic. Also, Dats, Align, Utils etc.

0
Topic starter

I think im just going to put the brakes on this for now haha 🤣 learning a whole new programming language takes some time so i'll just wait haha.

0
Topic starter

@wano So im just trying to draw a simple window box, but i still get those errors. I included all the neccessary imports

 

import { RPM } from "../path.js"
import { Graphic } from "../../System/index.js";

const pluginName = "ShowText";
const inject = RPM.Manager.Plugins.inject;

// Start code here

this.exampleWindow = new RPM.Core.WindowBox(0, 0, 25, 15, 
{ 
    // The following options are optional
    content: new Graphic.Text("myText"), // The content is a Graphic.Base
    padding: [0, 0, 0, 0], // [x, y, x, h] for box padding
    limitContent: true // If checked, the content will be cut according to padding
});

drawHUD() 
{
    this.exampleWindow.draw();
}

 

Failed to load resource: net::ERR_FILE_NOT_FOUND

Text.js:43 Uncaught TypeError: Cannot read property 'v_tSize' of undefined

    at new Text (Text.js:43)

    at code.js:12

Platform.js:144 Uncaught TypeError: Cannot read property 'v_tSize' of undefined

    at new Text (Text.js:43)

    at code.js:12

 

Wano Wano 01/05/2023 7:40 pm

@chay-hawk You shouldn't put this code directly like that. Plugins code is excecuted before loading any game data. The error is just telling that the window skin setting isn't loaded yet so you can't create a Graphic.Text before. Best practice is to put code to excecute in a class, and/or use inject method to edit code that is directly inside the original game code, so this code is excecuted after loading game data.

chay.hawk Topic starter 02/05/2023 6:44 am

Now that I think about it, I should just be able to directly edit the UI by modifying the games code right? I see all those files in VS Code from opening the folder the tutorial told me to open, I think it would be better to just do it that way honestly. I didn't mess with any of it because I didn't know if it will break the engine at all, but if I can just do that then I will.

Wano Wano 02/05/2023 9:15 pm

@chay-hawk You shouldn't. After each update from RPM, the game scripts are automatically updated, so you will lose everything you wrote. Everything is saved into another older folder, but your scripts might miss some updates.

Share: