Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Code works, but is SUPER slow..... help! [VX]

Ok so i'm working on my Menu systems right? I FINALLY get it doing what I want to do.... but it is so slow even my rig can barely handle it (and i'm on a AMD Phenom with 8 gigs of RAM).

so heres where I think the problem is:


 
Code:
def update
    super
    aaaaa = $game_party.members.size
    update_menu_background
    @command_window.update
    if @command_window.active
      update_command_selection
    
    for actor in $game_party.members
    create_newstat_window (aaaaa)
    aaaaa = aaaaa - 1 
    end
      
    elsif @status_window.active
      @status_window.update
      update_actor_selection
    end
  end

I'm calling for it to create new_stat_window in the for loop because everytime its run with a different number allowing for the script to display all 4 characters hitpoints etc. dynamicly on the bottom of the screen, while the window is up.

Heres the whole thing...its a bit of a mess, but I did my best to clean it up for you...

basicly as I was explaining all its doing is putting a small box on the bottom of the screen. Right now it just shows the player name and their position in the party, although its eventually going to show their name, HP, and MP.

Code:
module Wor_Litemenu

  MENU_WINDOW_Y = 20
  CHARA_WINDOW_Y = 80
  CHARA_WINDOW_WIDTH = 175
  SHOW_LV = false
  SHOW_LOCATION_WINDOW = false
  VOCAB_LOCATION = "Location:"
  VOCAB_GOLD = "Gold:"
  LOCATION_WINDOW_Y = 295
  LOCATION_TEXT_X = 96
  GOLD_TEXT_X = 84
end

class Scene_Menu < Scene_Base

  def initialize(menu_index = 0)
    @menu_index = menu_index
    
  end

  def start
    
    super
    
    create_menu_background
    create_command_window
    lite_create_location_window if Wor_Litemenu::SHOW_LOCATION_WINDOW == true
    lite_create_actor_window

  end

# START LITE METHOD
  def lite_create_actor_window
    
    
    member = []
    @item_max = $game_party.members.size
    for actor in $game_party.members
     member.push ((actor.name) + " Lv." + (actor.level.to_s)) if Wor_Litemenu::SHOW_LV == true
     member.push (actor.name) if Wor_Litemenu::SHOW_LV == false

     end
    @status_window = Window_Command.new(Wor_Litemenu::CHARA_WINDOW_WIDTH, member)
    @status_window.index = @menu_index
    @status_window.x = (304 /2) - (@status_window.width/2)
    @status_window.y = Wor_Litemenu::CHARA_WINDOW_Y
    @status_window.visible = false
    
    
  def lite_get_map_name
    mapdata = load_data("Data/MapInfos.rvdata")
    map_id = $game_map.map_id
    @map_name = mapdata[map_id].name
  end
  
  def lite_draw_currency_value(value, x, y, width)
    cx = @location_window.contents.text_size(Vocab::gold).width
    @location_window.contents.font.color = @location_window.normal_color
    @location_window.contents.draw_text(x+53, y, @location_window.width+cx, 24, value, 0)
    @location_window.contents.font.color = @location_window.system_color
    @location_window.contents.draw_text(x+(($game_party.gold).to_s.size * 8)+68, y, @location_window.width, 24, Vocab::gold, 0)
  end
  
  def lite_create_location_window
    width = 300
    height = 90
    x = (304 /2) - (width/2)
    y = Wor_Litemenu::LOCATION_WINDOW_Y
    @location_window = Window_Base.new(x, y, width, height)
    @location_window.create_contents
    lite_get_map_name
    @location_window.contents.font.color = @location_window.system_color
    @location_window.contents.draw_text(0, 0, 300, 24, Wor_Litemenu::VOCAB_GOLD)
    @location_window.contents.font.color = @location_window.normal_color
    lite_draw_currency_value($game_party.gold, 4, 0, Wor_Litemenu::GOLD_TEXT_X)
    @location_window.contents.font.color = @location_window.system_color
    @location_window.contents.draw_text(0, 32, 300, 24, Wor_Litemenu::VOCAB_LOCATION)
    @location_window.contents.font.color = @location_window.normal_color
    @location_window.contents.draw_text(Wor_Litemenu::LOCATION_TEXT_X, 32, 300, 24, @map_name)
  end
  
def create_newstat_window (actorcount)
    
    member = []
    hitpoints = []
    @item_max = $game_party.members.size
    for actor in $game_party.members
    member.push (actor.name) 
    hitpoints.push (actor.hp)
    end  
  
    width = 100
    height = 100
    x = ((225*actorcount) /2) - (width/2)
    y = Wor_Litemenu::LOCATION_WINDOW_Y
    @newstat_window = Window_Base.new(x, y, width, height)

    
    @newstat_window.create_contents
    @newstat_window.contents.font.color = @newstat_window.system_color
    @newstat_window.contents.draw_text(0, 0, 300, 24, member[actorcount])
    @newstat_window.contents.font.color = @newstat_window.normal_color
    @newstat_window.contents.draw_text(0, 30, 300, 24, actorcount)
    
    
  end

# END LITE METHOD

  def terminate
    super
    dispose_menu_background
    @command_window.dispose
    @location_window.dispose if @location_window
    @status_window.dispose
    @newstat_window.dispose
  end
  
  def update
    super
    aaaaa = $game_party.members.size
    update_menu_background
    @command_window.update
    if @command_window.active
      update_command_selection
    
    for actor in $game_party.members
    create_newstat_window (aaaaa)
    aaaaa = aaaaa - 1 
    end
      
    elsif @status_window.active
      @status_window.update
      update_actor_selection
    end
  end

  def create_command_window
    s1 = Vocab::item
    s2 = Vocab::skill
    s3 = Vocab::equip
    s4 = Vocab::status
    s5 = Vocab::save
    s6 = Vocab::game_end
    @command_window = Window_Command.new(200, [s1, s2, s3, s4, s5, s6],2,3)
    @command_window.index = @menu_index
    @command_window.x = (304 /2) - (@command_window.width/2) #167
    @command_window.y = Wor_Litemenu::MENU_WINDOW_Y
    
    end
    
    if $game_party.members.size == 0
      @command_window.draw_item(0, false)
      @command_window.draw_item(1, false)
      @command_window.draw_item(2, false)
      @command_window.draw_item(3, false)
    end
    if $game_system.save_disabled
      @command_window.draw_item(4, false)
    end
  end

  def start_actor_selection
    @command_window.active = false
    @status_window.visible = true
    @status_window.active = true
    @status_window.index = 0
  end

  def end_actor_selection
    @command_window.active = true
    @status_window.visible = false
    @status_window.active = false
    @status_window.index = -1
  end
  
end

so my real question is.... How do I speed it up?
 

khmp

Sponsor

All right a walk through perhaps?

We call super which calls the ancestor's update method's call. For a Scene class its supposed to be there. After that we initialize an oddly named variable to the number of actors in your party. Update the menu background does nothing by default. So thats not the cause. If the command window is active do such and such work, good, good. Alright for loop through the members and create a window... No that already sounds bad. Let's actually see what that method does. Oh no it creates a window.

The method coined "update" is called update because it is called rather frequently. Every time command window is active in the update we create a window for each character.

First time update runs we create a window for each character.
Second time update runs we create a window for each character.
Ad infinitum

That's your reason for lag. You need to move that window creation code to a method that is called once when a scene is created. Perhaps stick that for loop window creation code inside start?

Good luck with it strager! :thumb:
 

khmp

Sponsor

I'm actually a little confused on how it is meant to work. The last one stays in view because they all reference the same instance variable. Like say I had this:

Code:
@a = 5
@a = 3
@a = 4
print a # prints 4

That's what is happening with your windows. The code that was given to you was only meant to show one window at a time even though the x position initialization is misguiding in that its based on the actor's location in the party. Like if she/he were last in the party their window would be on the far right. If they were first in the party their window would be on the far left. Do you want it to show every part member's status at the same time?
 
khmp":tptr343g said:
I'm actually a little confused on how it is meant to work. The last one stays in view because they all reference the same instance variable. Like say I had this:

Code:
@a = 5
@a = 3
@a = 4
print a # prints 4

That's what is happening with your windows. The code that was given to you was only meant to show one window at a time even though the x position initialization is misguiding in that its based on the actor's location in the party. Like if she/he were last in the party their window would be on the far right. If they were first in the party their window would be on the far left. Do you want it to show every part member's status at the same time?

Well I want it to show it like that.

so basically while the menu is open it should across the bottom 4 small menus. They should be in the same order as the characters are in the party. So if you put the second actor in the first position the menus would switch- that's why I did it that way.
 
Forgot to add that if there are less party members than 4, it should only show 3 boxes, or 2 boxes, or 1 box. The boxes should always align to the right side of the screen (so if theres only 1 box it should be near the lower right corner. If there's 2 they will be in the lower right 2 positions etc.)

The script as it is now does all that if you want to see what I mean load it up (it should work independant of any other scripts) its just majorly slow.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top