Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

RenJS

HTML5 Visual Novel creation made easy and free · By lunafromthemoon

How do I use an input variable as character name ?

A topic by Yuna_x created Jan 09, 2020 Views: 319 Replies: 2
Viewing posts 1 to 2

Hello !

I just started to use RenJS so i'm sorry if my question looks stupid but we tried a bit everything we" knew".  I m  currently learning javascript so maybe there is something i could do I didn't know.

I just wanted the name written in the input to show in the name box. I could do that because i found it here in the forum.  This is my code :

  - text: Please write the name you wish to use.
  - call showInput:
  - text: My name will be {username}
  - play morningBGM:
  - show halfway: WITH FADE CONTINUE

So I tried :

- {username} says: blabla..

But it didn't work, I don't think it's impossible to show the input name.

Developer(+1)

Hello Yuna, it's easy to do, but you'll have to use a call function to set the name.

First, the characters have two names, an id, which is used in the script, and a name that will be shown in the name box. The id can never change, so if you have a character that represents the player, you can use, for example, "player" as the id. What you need to do is change the name property of the character so that when you make them talk, the new name will appear in the name box, instead of "player".

The characters are their own object, and the property for the display name is called "name". The characters are all stored in a map, accessible from the Character Manager (RenJS.chManager.characters), and you access each one indexed by their id. On the other hand, the variables are stored also in a map, in the Logic Manager (RenJS.logicManager.vars). Knowing this, it's easy to make a custom function to change a character name.

I'll give you an example with the Quickstart. The character with id "deuzi" has a displayName property defined in the setup as "Deuzilene".

Setup.yaml

characters:
  deuzi:
    displayName: Deuzilene
    speechColour: "#ca90cf"
    looks:
      normal: assets/characters/Char3Normal.png
      happy: assets/characters/Char3Happy.png

Story.yaml

start:
  - play morningBGM:
  - show room: WITH FADE CONTINUE
  - show deuzi: happy AT CENTER WITH FADE
  - var username: Sandrine
  - deuzi says: I prefer to be called by my middle name, {username}.
  - call changeName:
      character: deuzi
      name: username
  - deuzi says happy: That's much better!

In this case I just used a normal variable to store the new name, but you will use the one obtained from the input. The new name will appear only after calling the function changeName, with two parameters, the character id (deuzi), and the variable where we have the new name (username). In this way, you can change any name you want. Finally, let's see what's inside the changeName function:

CustomContent.js

RenJS.customContent = {
    //put here your own functions
    changeName: function (params) {
        //params is a map with {character,name}
        //lookup of the character with "character" id
        var character = RenJS.chManager.characters[params.character];
        //lookup the content of the variable with "name" id
        var newName = RenJS.logicManager.vars[params.name];
        //change the character name property
        character.name = newName;
        //continue with the game
        RenJS.resolve();
    }
}

Hope you can make it work, and let me know if there's more I can help you with.

Cheers!

Luna

Hello Luna

It worked, I'm really happy !

Thank you very much Luna for your fast help and also for developping RenJS. I always wanted to make my own visual novel and i really enjoy using this.

Yuna ~