SpaceTraveller97

Villager
Member
Joined
Feb 5, 2021
Messages
21
Reaction score
1
First Language
Spanish
Primarily Uses
RMMV
I'm trying to get the digits value of a variable, example: var value is 25 and i want to get 5. How can i do this?
Why i want this? I'm calling pictures of numbers by script call
 
Last edited:

ShadowDragon

Realist
Veteran
Joined
Oct 8, 2018
Messages
4,676
Reaction score
1,797
First Language
Dutch
Primarily Uses
RMMV
so you want a variable value to check if the number is 5?

like this conditional branch:

if: variable 4 = 5
show picture x
end

something like this? or something more complex?
because if you want a variable based on number, there was a thread how
to do that, but this also require the images to have a number in order to show.

but you need to explain a bit more in detail what you exactly want to achieve,
otherwise, you can go many ways, and probably my example isn't what you need.
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
965
Reaction score
470
First Language
PT-BR
Primarily Uses
RM2k3
Welcome!

See this:
 
Last edited:

SpaceTraveller97

Villager
Member
Joined
Feb 5, 2021
Messages
21
Reaction score
1
First Language
Spanish
Primarily Uses
RMMV
What i want is more complex, that way i'll need like 1000 conditional branch or more. I'm using a script to show these pictures but if i want to show the pictures of the numbers with two digits or more i need to call another picture and it must have the value of the second digit that variable
so you want a variable value to check if the number is 5?

like this conditional branch:

if: variable 4 = 5
show picture x
end

something like this? or something more complex?
because if you want a variable based on number, there was a thread how
to do that, but this also require the images to have a number in order to show.

but you need to explain a bit more in detail what you exactly want to achieve,
otherwise, you can go many ways, and probably my example isn't what you need.
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
965
Reaction score
470
First Language
PT-BR
Primarily Uses
RM2k3
Plugin basic (checkVarDigit.js):
JavaScript:
function checkVarDigit(gamevar,pos){
    var chkvar=$gameVariables.value(gamevar);
    chkvar = chkvar.toString(); /*Convert in String*/
    chkvar = chkvar.split(''); /*Convert in Array*/
    return Number(chkvar[pos]);
}

How use (Variable 10 on Example):
Code:
if(checkVarDigit(10,1) == 2){
   alert("Equal");
}

Conditional Branch:
Code:
◆If:Script: checkVarDigit(10,1) == 2
   ◆Message: Hello!
   ◆
:End

Variable 10 with value 1245790
Pos 0 = 1
Pos 1 = 2
Pos 2 = 4
Pos 3 = 5
Pos 4 = 7
Pos 5 = 9
Pos 6 = 0
 
Last edited:

SpaceTraveller97

Villager
Member
Joined
Feb 5, 2021
Messages
21
Reaction score
1
First Language
Spanish
Primarily Uses
RMMV
Im using this script call:

JavaScript:
$gameScreen.showPicture(32, 'num' + $gameVariables.value(61), 0, 10, 15, 100, 100, 255, 0)

Num is the picture, there are 10 (0 to 9) and $gameVariables.value(61) is the variable that i want the pictures of numbers show

Plugin basic (checkVarDigit.js):
JavaScript:
function checkVarDigit(gamevar,pos){
    var chkvar=$gameVariables.value(gamevar);
    chkvar = chkvar.toString(); /*Convert in String*/
    chkvar = chkvar.split(''); /*Convert in Array*/
    return Number(chkvar[pos]);
}

How use (Variable 10 on Example):
Code:
if(checkVarDigit(10,1) == 2){
   alert("Equal");
}

Conditional Branch:
Code:
◆If:Script: checkVarDigit(10,1) == 2
   ◆Message: Hello!
   ◆
:End

Variable 10 with value 1245790
Pos 0 = 1
Pos 1 = 2
Pos 2 = 4
Pos 3 = 5
Pos 4 = 7
Pos 5 = 9
Pos 6 = 0
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,965
Reaction score
2,294
First Language
EN
Primarily Uses
RMMZ
You can do this with variable operations alone:
  • Div returns the result after dividing by the operand, rounded down to the nearest integer;
  • Mod returns the remainder after dividing by the operand.
Together these can be used to get the value of any digit, e.g.

◆Text:None, Window, Bottom : :Enter a number! ◆Input Number:Count, 3 digits ◆Control Variables:#0017 check = Count ◆Control Variables:#0017 check %= 10 ◆Text:None, Window, Bottom : :Units digit is \v[17] ◆Control Variables:#0017 check = Count ◆Control Variables:#0017 check /= 10 ◆Control Variables:#0017 check %= 10 ◆Text:None, Window, Bottom : :Tens digit is \v[17] ◆Control Variables:#0017 check = Count ◆Control Variables:#0017 check /= 100 ◆Control Variables:#0017 check %= 10 ◆Text:None, Window, Bottom : :Hundreds digit is \v[17]

[Edit: whoops, I should have checked the link Dev_With_Coffee posted before replying. :kaoslp:]
 
Last edited:

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
965
Reaction score
470
First Language
PT-BR
Primarily Uses
RM2k3
Or this:
Welcome!

See this:

Example with 4 digits:
Code:
◆Comment:---------------------------------------------------------
◆Control Variables:#0062 A*** = Var #0061
◆Control Variables:#0063 *B** = Var #0061
◆Control Variables:#0064 **C* = Var #0061
◆Control Variables:#0065 ***D = Var #0061
◆Comment:---------------------------------------------------------
◆Control Variables:#0062 A*** /= 1000
◆Control Variables:#0063 *B** /= 100
◆Control Variables:#0064 **C* /= 10
◆Comment:---------------------------------------------------------
◆Control Variables:#0062 A*** %= 10
◆Control Variables:#0063 *B** %= 10
◆Control Variables:#0064 **C* %= 10
◆Control Variables:#0065 ***D %= 10
◆Script:$gameScreen.showPicture(31, 'num' + $gameVariables.value(62), 0, 10, 15, 100, 100, 255, 0)
◆Script:$gameScreen.showPicture(32, 'num' + $gameVariables.value(63), 0, 20, 15, 100, 100, 255, 0)
◆Script:$gameScreen.showPicture(33, 'num' + $gameVariables.value(64), 0, 30, 15, 100, 100, 255, 0)
◆Script:$gameScreen.showPicture(34, 'num' + $gameVariables.value(65), 0, 40, 15, 100, 100, 255, 0)
 

Latest Threads

Latest Posts

Latest Profile Posts


It's a Spanish devlog don't get scared!.
Just read the forum rules just for kicks and rule 14 reminds me of this:
150.jpg
I'm in the process of converting all locks and intimidate/persuade dialogue options into D20 DC based success/fail (modified by player skill). Before, it required a certain flat amount you had to meet, but with rolls, it offers more freedom. For instance, you can repeatedly try to unlock a door instead of just not meeting the requirement to unlock it.
Since we get very close: If you want to enjoy the advent calendar as it is intended, wait til your date and the day in the URL line up, so you have the final day on actual christmas and not the day before... time zones ;3
1638170340913.png
Crossover Inn is getting very crowded, and I love it

Forum statistics

Threads
117,050
Messages
1,104,158
Members
153,014
Latest member
Nastyboydima
Top