Problem: Collecting variables into one

Discussion in 'RPG Maker XP' started by Alexaaskov, Jun 8, 2018.

    Tags:
  1. Alexaaskov

    Alexaaskov Somewhat New Member

    Messages:
    2
    Likes Received:
    0
    First Language:
    Danish
    Primarily Uses:
    RMXP
    So I have been tinkering with variables in RMXP and it hasn't exactly been easy. Most forums that helps with variable-related problems doesn't use RMXP. I have been trying to add the content of one variable to another variable.

    I don't mean something like:
    Var(3) = Var(1) + Var(2)

    But something like:
    Var(1) = [1, 2, 3] & Var(2) = [4, 5, 6]
    Var(3) = [Var(1), Var(2)] = [1, 2, 3, 4, 5, 6]

    When I try this my third variable becomes [123,456] instead. A forum on "Support/JavaScript Boards/Learning JavaScript" posted by Llareian was talking about this problem and came up with an solution. I tried to modify the solution for RMXP, but I don't seem to have the functions they use. Any suggestions are appreciated.

    Solution for Llareian:
    if ( !$gameVariables.value(15) ) { $gameVariables.setValue(15, []) };
    $gameVariables.value(15).push( $gameVariables.value(16) );
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    26,948
    Likes Received:
    5,891
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    this can't be done directly due to the way variables are stored.

    By default each variable can hold only a single value. you can redefine that to a different form of a variable (like the array variable you propose), but then you need to access that variable as an array as well - and that usually requires more steps.
    for example your first idea needs to be split into first a redefinition of var 1 into an array variable, then three steps adding the content of var 2 to each elements of the array in var 1.
    that simply cannot be done in a single command.

    and in all cases XP uses a ruby-variant called RGSS - you can't use javascript code in XP. Those are two entirely different programming languages.
     
    #2
  3. Alexaaskov

    Alexaaskov Somewhat New Member

    Messages:
    2
    Likes Received:
    0
    First Language:
    Danish
    Primarily Uses:
    RMXP
    Thank you for the respons. I hadn't found out exactly what the coding language was called in RMXP, so that helps.
    It is unfortunate that there is no simple function to do this. I will try and make something with loops, so I don't have to write a line of code each time I want to add to my variable.
     
    #3
  4. Shaz

    Shaz Veteran Veteran

    Messages:
    36,673
    Likes Received:
    10,663
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    $gameVariables.value(15)

    This is also the MV way of using variables. In RMXP, it is $game_variables[15] = ...
    There is no .value and .setValue - in XP you are accessing the variables array/data directly, not via functions (kind of)
     
    #4
  5. Another Fen

    Another Fen Veteran Veteran

    Messages:
    500
    Likes Received:
    221
    First Language:
    German
    Hey there,

    If both of your variables var1 and var2 hold arrays, you can actually combine them using the plus sign:
    Code:
    var1 = [1, 2, 3]
    var2 = [4, 5, 6]
    var3 = var1 + var2  # => [1, 2, 3, 4, 5, 6]
    Don't know if it helps here, but for an overview/documentation of the standard library you can look here (this one is for Ruby 1.8.7 though. RMXP uses 1.8.1, which is unfortunately not documented there, but almost everything is still applicable).

    $game_variables allows you to access the set of variables also used in events. They come in handy if you want an easy way to save something with the rest of the savestate for example, and can be treated like other variables apart from that.
     
    #5
    Shaz likes this.

Share This Page