How to split a number in separate variable

Discussion in 'RPG Maker VX Ace' started by Emmabelotti, Jan 8, 2019.

  1. Emmabelotti

    Emmabelotti Villager Member

    Messages:
    12
    Likes Received:
    1
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Hello guys :D!
    I have a question:is there a way to collect a line of numbers from the player and then split it into tons of different variables?
    An example:
    insert a number
    >123 - 456
    A:1 B:2 C:3
    D:4 E:5 F:6
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    26,948
    Likes Received:
    5,891
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    yes, there is a number input command in the events, and after that it's just mathematics with control variable command.
    More precisely you'll need modulo operations (the fifth basic mathematic operation after addition, substraction, multiplication and division)
     
    #2
    Emmabelotti likes this.
  3. Emmabelotti

    Emmabelotti Villager Member

    Messages:
    12
    Likes Received:
    1
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Thanks for the answer!
    Another problem:what if i use Letters insted of numbers? Is there a way to convert them into a variable value?
     
    #3
  4. Andar

    Andar Veteran Veteran

    Messages:
    26,948
    Likes Received:
    5,891
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    only by script use (the other solution above is pure eventing), and even then you'll need to be good with logic and data conversion.
     
    #4
  5. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    547
    Likes Received:
    132
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    You might be able to save that number in a dummy character name used solely for that purpose. However, as it has been said, you have to convert text to numbers using ruby. While you can use a character name to store a text input you cannot convert that said text without using some sort of ruby coding. There are different ways of achieving that.
    Code:
    my_integer = my_string.to_i
    my_array = my_string.scanf("%d") # this is an array containing a single integer
    my_integer = my_array[0]
    The previous lines are both examples of how to convert a string variable - that can be your dummy character name - into an integer (that can be any variable).
    I would not recommend using a string to get a number though. If the only acceptable input is a number you should use numbers, that way the player cannot insert random characters like "12346kjhsdfshubdsf346#$@". If you allow the usage of strings that thing is a string and as such it is possible to insert something like that too.
     
    Last edited: Jan 9, 2019
    #5
  6. Emmabelotti

    Emmabelotti Villager Member

    Messages:
    12
    Likes Received:
    1
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    The bad thing is...
    I can't read ruby :rsad:

    My idea was to make a long-password-like system (just like those old nes games) but i can't figure out how to insert that password. 10 numbers (0-9) + 2 alphabets (upper and lower case) for 49+3/25+3 variables are a pain to add in a game using events for every single letter (and writing a letter a time will be as painful for the player aswell):hsad:
     
    #6
  7. Emmabelotti

    Emmabelotti Villager Member

    Messages:
    12
    Likes Received:
    1
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    I may just make it longer but with only numbers if it sounds easier,but it will make the password really long ._.
    If someone knows if you can do that using letters,he will save my life!
     
    #7
  8. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    547
    Likes Received:
    132
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    as I said you can just let the player enter a name for a dummy character and use that for comparison. If you save it that way you do not need to split it later on, do you?
    Just compare that character name with the password you want using a simple conditional branch and that's it.

    That said if you need those characters to be handled separately but still act as some sort of password you can still split them and have them stored in different variables. If all you have to do is just this:

    1. Save your character in a variable
    2. Check if that character is equal to what you want it to be
    3. Do something if the previous is true
    4. Repeat for each character
    Then you don't have to be careful about what the player is going to insert as character name nor you have to handle that string carefully since you won't be using anything other than the first N characters (N is your password length).

    Anyway to split it you still need to write some lines in ruby, like it or not. Splitting a string is not the same as splitting a number (which can be done by just using the modulo operator and applying an integer division by 10 on the number itself multiple times until that number becomes 0). Strings are not numbers so you can either slice them or access single characters contained in them but you can't do that by just using math.
     
    Last edited: Jan 9, 2019
    #8
  9. Emmabelotti

    Emmabelotti Villager Member

    Messages:
    12
    Likes Received:
    1
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Thanks for the reply! I guess i have to learn ruby,then
     
    #9
  10. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    547
    Likes Received:
    132
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    I am not saying you have to learn it, I am just saying you have to use it. Basically everything that is not done via event commands can be done using ruby but you have to know how.

    In this forum people can help you providing lines of code you need but then you have to adapt them to your situation. What I wrote in my previous post is a clear example. People helping you cannot know which variable/switch you are going to use nor which character you are going to use to store that password of yours.

    That applies to everyone who asks for help as well. Nobody can read the thoughts of those who ask for help and so we can only provide some generic way of doing it. You are the one who has to adapt those line to that situation.

    If you want to store something in your variable 9 and you ask how to save something in a variable using a script call I can answer you this:
    Code:
    $game_variables[your_variable_id] = something
    If you add that to a script call you'll find that it DOES NOT work. It does not work because it is meant to be generic. Your game has no idea of what "your_variable_id" is. That is supposed to be your variable ID that only you know.

    To have the code working you have to change your_variable_id with 9. If you do that in your game it will look like this:
    Code:
    $game_variables[9] = something
    Now, it still won't work because there is no such a thing as "something" in your game, but if you change that "something" to be a number, a string, a character or anything that does actually exist then it will have some effect. You can give it a try if you want. Just put a number or a string instead of it and then display your variable in a message. You'll see how your variable value changes depending on what you write there.

    That is exactly what I meant. We can provide you the code but you have to know how to edit it to fit your project.

    In any case you will often find instructions in the code itself after a "#". That is because everything after a "#" in a ruby line is a comment and does not work as executable code so programmers use them to write instruction and other useful informations inside the code itself.

    As a side note, the scanf line I used in one of my previous posts can be used to achieve what you need if properly modified.
     
    Last edited: Jan 9, 2019
    #10
    Wavelength likes this.
  11. Emmabelotti

    Emmabelotti Villager Member

    Messages:
    12
    Likes Received:
    1
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    Thanks for the answer,only now i understood your idea of using characters instead of convert them. Imo that's very clever,and i Will be able to do 90% of the work in rpg maker's event without addictional code :oswt:
     
    #11
  12. Heirukichi

    Heirukichi Veteran Veteran

    Messages:
    547
    Likes Received:
    132
    Location:
    Italy
    First Language:
    Italian
    Primarily Uses:
    RMVXA
    That's how it is unless you want to do something very specific. The engine itself already allows you to do a lot of things. However if you need help when comparing your strings feel free to ask.
     
    #12

Share This Page