How to check a variable's digit?

Rink27

Veteran
Veteran
Joined
Jul 18, 2014
Messages
222
Reaction score
13
First Language
English
Primarily Uses
RMMV
◆Control Variables:#0237 Delivery Time = 56789
◆Script:var x = $gameVariables.value(237);
: :var y = 3;
: :
: :if (y = 4) {
: :var z = String(x).charAt(2);
: :} else if (y = 3) {
: :var z = String(x).charAt(1);
: :} else {
: :var z = String(x).charAt(0);
: :}
: :$gameVariables.setValue(239,y);
: :$gameVariables.setValue(240,z);
◆Text:None, Window, Bottom
: :Value: \V[240]<br>
: :Length: \V[239]

On the second script line I had coding to obtain the length, but I noticed it always gave a length of 4. So I hard coded it to a length that wasn't 4 and still got 4. What am I doing wrong?

----
Also, I can't access the "Javascript that don't deserve their own thread" thread. I keep getting an Error message.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,392
Reaction score
12,917
First Language
English
Primarily Uses
RMMV
=== is used to compare. = is used to assign.

if (y = 4) is always going to evaluate to true, because it assigns the value of 4 to the variable y, then returns true to say the assignment was successful.
 

Rink27

Veteran
Veteran
Joined
Jul 18, 2014
Messages
222
Reaction score
13
First Language
English
Primarily Uses
RMMV
=== is used to compare. = is used to assign.

if (y = 4) is always going to evaluate to true, because it assigns the value of 4 to the variable y, then returns true to say the assignment was successful.
I realised my mistake soon after (but couldn't access my own thread because of that forum error). I'm embarrassed having made this thread, lol. I'd blame my sleepiness at the time. Btw...

◆Script:var x = 12345;
: :var member = x.toString().length;
: :var last = member.substring(member.length - 2, member.length)
: :$gameVariables.setValue(240, last);

What I was experimenting with was ways to do a conditional on the last two digits of any number (I was trying to work with the second to last digit). My solution was simply:


◆Script:var x = $gameVariables.value(237) % 100;
: :$gameVariables.setValue(240, x);

But I was running into errors using that substring method. I was confused between substr and substring though. I think one was jQuery, and I'm not even sure if that could work with MV.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,392
Reaction score
12,917
First Language
English
Primarily Uses
RMMV
Yeah, easiest way is just to do % 100 :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

This time around I don't have early access to the new maker, so I have to wait like everyone else to look under the hood. I really hope we get to soon though, I'm pretty excited :D
Chaos17 wrote on Poryg's profile.
Hi, I am following your videos tutorials serie about coding on MV and I am at the third video. Thank you for making it but's a bit hard to follow since you don't show the whole plugin at the end. I had to screenshot the lines between 110-159 because you scrolled so fast on them.
:rtear:
I'm not sure if I should be happy for MZ, or sad for MV.
Not going to lie.... The update's cool and all, but I immediately ran to Mog's site and was like, "Update! Update! Update!" while breathing on the page of his Star Ocean Battle System plugin. :kaoswt:
Ho boi. I can already see the storm of ugly actor faces RTP customizable facesets from MZ are gonna flood. XD

Forum statistics

Threads
99,463
Messages
965,684
Members
131,073
Latest member
James1998
Top