MZ Hello, please help me with this variable value.

[IMG]https://files.catbox.moe/v3oz5s.png[/IMG]
To put it simply, when the value of variable 176 is more than 4 digits, i only want the first four digit to put in the variable value.

But i don't know how, i'm really bad at javascript... I've done it with substrings too. But the same result, nothing changed 🙂

Got any suggestion what should i change in the script?

Thanks!
Got any suggestion what should i change in the script?
change the variable into a string, slice the string, save it, then make it an int again.


Code:
$gameVariables.setValue(176, String($gameVariables.value(176)))
$gameVariables.setValue(176, $gameVariables.value(176).slice(0, 4))
$gameVariables.setValue(176, parseInt($gameVariables.value(176)))
that should work for what youre trying to do
It's done now! Thank you for your help robro!
why use script at all?
that could easily be done with a combi8nation of the default control variable operations divide by and modulo
Never tried that before hehe, but i'll check it next time, it'd save my time a lot if its true 🙂 thanks for the advice!
It's certainly doable with just event commands, but I can't think of a way that wouldn't be more lines than the code above.

I also can't think of what Andar has in mind without having to use additional variables and loops.
In particular, note that this Script command:

$gameVariables.setValue(176, $gameVariables.value(176) / 3);
...is essentially equivalent to: Control Variables -> Div -> Constant -> 3.

Some advantages of using the Control Variables command instead of Script:
  • You don't have to know anything about JavaScript;
  • It's easier to input without mistakes;
  • It can be found using Tools -> Event Searcher;
  • It is more likely to remain compatible with plugins (e.g. self-variables);
  • It doesn't get re-compiled every time.

To extract the first 4 digits of a number without a script call, I think you'd just need a loop, e.g.

◆Control Variables:#0001 Value = 0 ◆Input Number:Value, 8 digits ◆Loop ◆If:Value > 9999 ◆Control Variables:#0001 Value /= 10 ◆ :Else ◆Break Loop ◆ :End ◆ :Repeat Above ◆Text:None, None, Window, Bottom : :First four digits are \v[1].
If you wanted to preserve the original value, you could set a second variable equal to the first one, then operate on that second variable instead.
Woah i see... So you could do that, i never thought of that before but really thanks guys, that's helpful! Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/hello-please-help-me-with-this-variable-value.157171/