JavaScript Help with .concat and randomly generating 3 numbers

I'm trying to concatenate a number so that it ends in the number 5 with JavaScript, but alas my understanding of java and how it works in RPGMaker means I'm having no

I wanted to have so you get a hint at three digits random digits and have to figure out the third digit by other information you run across exploring the cave.

Crude understanding of java I came up with this:
JavaScript:
var a = String($gameVariables.value(100))
a.concat("5")
$gameVariables.value(100) = Number(a)

Am I even close to pulling it off or am I not even on the planet?


I'm also having trouble random generating a 3 digit number as a zero in the hundreds place.

And anyway to strip the comma out of the text when using \v[]?

Thanks,
Jomei
I'm trying to concatenate a number so that it ends in the number 5 with JavaScript, but alas my understanding of java and how it works in RPGMaker means I'm having no

I wanted to have so you get a hint at three digits random digits and have to figure out the third digit by other information you run across exploring the cave.

Crude understanding of java I came up with this:
JavaScript:
var a = String($gameVariables.value(100))
a.concat("5")
$gameVariables.value(100) = Number(a)

Am I even close to pulling it off or am I not even on the planet?


I'm also having trouble random generating a 3 digit number as a zero in the hundreds place.

And anyway to strip the comma out of the text when using \v[]?

Thanks,
Jomei
$gameVariables.value(x) is a getter, not a setter. You can't set the value using it; you need to use setValue.

The way I would personally do this is

JavaScript:
const firstDigits = $gameVariables.value(100).toString();
$gameVariables.setValue(100, parseInt(firstDigits + "5"));

I'm not sure what you mean with the second one. Do you mean that if you generate a number less than 100 it fills the leftover digits with 0s?

The comma in the text isn't default behaviour; it's added by a plugin, so you'll need to figure out which plugin in order to identify how to prevent it.
I'm trying to concatenate a number so that it ends in the number 5 with JavaScript, but alas my understanding of java and how it works in RPGMaker means I'm having no
Trihan's script will of course work fine for this, but you could also just multiply the number by 10 and then add 5 with regular event commands.
Trihan's script will of course work fine for this, but you could also just multiply the number by 10 and then add 5 with regular event commands.
That's a great point. I was so focused on giving OP what they asked for I forgot to consider better alternatives. XD

That said, if they do want to use 0-padding on the left, it's better to use the string conversion method since padZero returns a string anyway; saves the need for multiple casts.
Thank again Trihan, besides the syntax error on my part. Every example showed converting using String() and not the .toString() method.

Also for scripting do the rules of using ; apply

I saw parseInt, but no info on use. Thanks again. While Mac slammed it with the easiest. On the Java side being able to do more with the variables is way more helpful as you don't have to use game variables saving those for other things.

Any rule of thumb between using Let and Const to define variables and anyway of saving them?
Any rule of thumb between using Let and Const to define variables
let will define a variable that can be changed later, while const will define one that can't be changed.
anyway of saving them
You can freely put strings and objects into game variables, and doing so is the simplest way of saving them. You can also add them to global scope (e.g. window.myVar = "hi" will make it so that myVar can be accessed anywhere), but those will not persist when the player saves and reloads the game.
On the Java side
Just to point it out because you've said this twice - RPG Maker uses JavaScript, not Java.

They have similar names but are two different programming languages. If you're trying to look up tutorials/examples in Java, that will lead to you having incorrect syntax for your MZ project.

Original thread: https://forums.rpgmakerweb.com/threads/javascript-help-with-concat-and-randomly-generating-3-numbers.165489/