[REQUEST] Script to change windowskin via a in-game variable

Discussion in 'RGSS Script Requests' started by xChikyx, Aug 7, 2019.

  1. xChikyx

    xChikyx Villager Member

    Messages:
    10
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMXP
    As the title says, i need a script that can change the windowsking based on an ingame variable. I tried doing it myself (modifying the game scripts), but i always get the same error of nil:NilClass when calling for the in-game variable $game_variables[15]
    can someone help me at least telling em how to address the variable properly?

    I think i could change it in here in Window Base:
    def update
    super
    if $game_system.windowskin_name != @windowskin_name
    @windowskin_name = $game_system.windowskin_name
    self.windowskin = RPG::Cache.windowskin(@windowskin_name)
    end
    end

    def update
    super
    if $game_system.windowskin_name != @windowskin_name
    @windowskin_name = $game_variables[15]
    self.windowskin = RPG::Cache.windowskin(@windowskin_name)
    end
    end

    and here in Game System:

    def windowskin_name

    if @windowskin_name == nil
    return $data_system.windowskin_name
    else
    return @windowskin_name
    end
    end

    def windowskin_name

    if @windowskin_name == nil
    return $game_variables[15]
    else
    return @windowskin_name
    end
    end

    But, of course that's not working...
    Is there a way to make it? can someone help me please?

    The Windowskin Files are called 1, 2,3 and 4. That's how i plan to call them with the variable
     
    Last edited: Aug 7, 2019
    #1
  2. bgillisp

    bgillisp Global Moderators Global Mod

    Messages:
    12,313
    Likes Received:
    12,536
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMVXA

    I've moved this thread to RGSSx Script Requests. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #2
  3. mlogan

    mlogan Global Moderators Global Mod

    Messages:
    13,849
    Likes Received:
    7,667
    Location:
    Texas
    First Language:
    English
    Primarily Uses:
    RMMV

    I've moved this thread to Script Requests. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #3
  4. DerVVulfman

    DerVVulfman Resident Werewolf Veteran

    Messages:
    309
    Likes Received:
    150
    First Language:
    English
    Primarily Uses:
    RMXP
    DIFFERENT approach.

    How about altering Game_Variables???

    Code:
      #--------------------------------------------------------------------------
      # * Set Variable
      #     variable_id : variable ID
      #     value       : the variable's value
      #--------------------------------------------------------------------------
      def []=(variable_id, value)
        if variable_id <= 5000
          @data[variable_id] = value
        end
        if variable_id == 15
          $game_system.windowskin_name = value.to_s
        end
        $game_map.need_refresh = true
      end
    
    Yeah, I added the need refresh line too. Just changing a variable (or a switch) does nothing to the map UNLESS the map refreshes.

    And the filename for the windowskin needed to be a string.
     
    #4
  5. xChikyx

    xChikyx Villager Member

    Messages:
    10
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMXP
    Thank you, but I found an easier way to do it using conditionals and the built-in change sking option hahah
     
    #5
  6. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    I think you can actually do it without any scripts, with simply doing a event/common event with parallel process that do an action when a game variable is on a number etc. with a conditional branch, like changing the windowskin. (sorry if i'm wrong)
     
    #6
  7. xChikyx

    xChikyx Villager Member

    Messages:
    10
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMXP
    no, yeah, you're actually right.
    It's even easier that way tbh
     
    #7
  8. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    np btw xd
     
    #8
  9. Shaz

    Shaz Veteran Veteran

    Messages:
    37,816
    Likes Received:
    11,523
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    The reason you got the error message in your first post is that $game_variables is not created until you select New Game or Continue from the title screen. But the title screen uses the windowskin. So you are trying to access something that hasn't been created yet.

    Also, I don't see why you need to have a parallel process common event. If the windowskin only changes when a variable changes, then you know exactly when the windowskin needs to be changed, so you don't need a parallel process (setting up too many of these, or even one, if not well designed, will cause your game to lag). Just have one common event that sets the windowskin based on the variable, which is not set to autorun or parallel process. Then whenever you have an event that changes that variable, follow it with a Common Event command, to call your common event.

    If your query is resolved, report your first post and let the mods know, so they can close the thread.
     
    #9

Share This Page