Item Problem

Hello,

i´m new here and i hope someone can help me. I found a old project from me after 4 years ( i think). That was a adventure game like monkey island. I don´t know from which person this engine was but ok. I want to make a new game as a adventure game. If i add a new item in the script "item18" the main character start to go slow. Funfact: If i use another items from 1-17 the person move normal but if i use item18 the person move slow. As a example i add all items 1-18 to my bag and if i scroll through my bag everytime i hit item18 the person start to move slow. I don´t know, i´m new, can i send a download link to my project?

Greets, VD
Yeah, a download link would be nice, because I have no idea what you're talking about honestly.
Just a screenshot of Item 18 in the database should do it, and a list of any scripts you've added to your project.
Yeah, a download link would be nice, because I have no idea what you're talking about honestly.
No problem


i made a testversion. You can switch the item with S and A and you can see that the game start to lagg if you hold the needle (item18) and here a video
Basically I narrowed it down to your common events being way too big. Funny thing is it's not all the conditionals leading up to drawing Item #18's picture; rather, it's all the Branch Ends it goes through that bogs it all down.

I'll see if there's a better way to implement what you want.

EDIT:
Here's a script that pretty much does what your two "Items" common events were doing.
Ruby:
module PlayerItems
  @@_items = []
 
  def self.add(id)
    @@_items[id] = true
    $game_variables[5] = id
  end
 
  def self.remove(id)
    @@_items[id] = nil
  end
 
  def self.has?(id)
    @@_items[id] == true
  end
 
  def self.update
    input_update
    picture_update
  end

  def self.input_update
    if @@_items.compact.empty?
      $game_variables[5] = -1
      return
    end
    $game_variables[5] = 0 if $game_variables[5] < 0
   
    i = $game_variables[5]
    if Input.trigger?(Input::X)
      $game_variables[5] = @@_items[0...i].rindex(true) ||
                           @@_items[i...@@_items.size].rindex(true) + i
    elsif Input.trigger?(Input::Y)
      n = @@_items[(i+1)...@@_items.size].index(true)
      $game_variables[5] = n ? n + i + 1 : @@_items[0..i].index(true)
    end
  end
 
  def self.picture_update
    pic = case $game_variables[5]
          when 0 then 'Kalisman'
          when 1 then 'Glaskugel'
          when 2 then 'Streichhölzer'
          when 3 then 'Messer'
          when 4 then 'Amulett'
          when 5 then 'Guitar'
          when 6 then 'Gold'
          when 7 then 'Monster'
          when 8 then 'Kerze'
          when 9 then 'Flasche'
          when 10 then 'Schlüssel'
          when 11 then 'Falschgeld'
          when 12 then 'Schlüssel'
          when 13 then 'Brief'
          when 14 then 'Wrbung'
          when 15 then 'BH'
          when 16 then 'Dietrich'
          when 17 then 'Kleingeld'
          when 18 then 'Pinnadel'
          end
   
    unless pic
      $game_screen.pictures[2].erase
      return
    end
   
    $game_screen.pictures[2].show("Picture_#{pic}",
      0, 512, 352, 100, 100, 255, 0)
  end
 
end
You can change your first Items common event into this
1651034945594.png

and remove the second Items common event entirely.

You had all these switches corresponding to items that the player possesses. So instead of turning on Switch 58 to give Item 18, you do this script call instead:
Code:
PlayerItems.add 18
Doing this will also update the variable 5 (PlayerItems) to 18. I figured this is what you wanted as you had set up your map event like this.

If you ever add more items to your game, all you have to do is add them to the big case-statement near the bottom of the script.

I didn't test this too much, so let me know what you need.

One more unrelated thing, in Scene_File, you need to add @Title.dispose to the end of your main method. Place it just above the line saying @pfeil.dispose
Basically I narrowed it down to your common events being way too big. Funny thing is it's not all the conditionals leading up to drawing Item #18's picture; rather, it's all the Branch Ends it goes through that bogs it all down.

I'll see if there's a better way to implement what you want.

EDIT:
Here's a script that pretty much does what your two "Items" common events were doing.
Ruby:
module PlayerItems
  @@_items = []
 
  def self.add(id)
    @@_items[id] = true
    $game_variables[5] = id
  end
 
  def self.remove(id)
    @@_items[id] = nil
  end
 
  def self.has?(id)
    @@_items[id] == true
  end
 
  def self.update
    input_update
    picture_update
  end

  def self.input_update
    if @@_items.compact.empty?
      $game_variables[5] = -1
      return
    end
    $game_variables[5] = 0 if $game_variables[5] < 0
 
    i = $game_variables[5]
    if Input.trigger?(Input::X)
      $game_variables[5] = @@_items[0...i].rindex(true) ||
                           @@_items[i...@@_items.size].rindex(true) + i
    elsif Input.trigger?(Input::Y)
      n = @@_items[(i+1)...@@_items.size].index(true)
      $game_variables[5] = n ? n + i + 1 : @@_items[0..i].index(true)
    end
  end
 
  def self.picture_update
    pic = case $game_variables[5]
          when 0 then 'Kalisman'
          when 1 then 'Glaskugel'
          when 2 then 'Streichhölzer'
          when 3 then 'Messer'
          when 4 then 'Amulett'
          when 5 then 'Guitar'
          when 6 then 'Gold'
          when 7 then 'Monster'
          when 8 then 'Kerze'
          when 9 then 'Flasche'
          when 10 then 'Schlüssel'
          when 11 then 'Falschgeld'
          when 12 then 'Schlüssel'
          when 13 then 'Brief'
          when 14 then 'Wrbung'
          when 15 then 'BH'
          when 16 then 'Dietrich'
          when 17 then 'Kleingeld'
          when 18 then 'Pinnadel'
          end
 
    unless pic
      $game_screen.pictures[2].erase
      return
    end
 
    $game_screen.pictures[2].show("Picture_#{pic}",
      0, 512, 352, 100, 100, 255, 0)
  end
 
end
You can change your first Items common event into this
View attachment 224414
and remove the second Items common event entirely.

You had all these switches corresponding to items that the player possesses. So instead of turning on Switch 58 to give Item 18, you do this script call instead:
Code:
PlayerItems.add 18
Doing this will also update the variable 5 (PlayerItems) to 18. I figured this is what you wanted as you had set up your map event like this.

If you ever add more items to your game, all you have to do is add them to the big case-statement near the bottom of the script.

I didn't test this too much, so let me know what you need.

One more unrelated thing, in Scene_File, you need to add @Title.dispose to the end of your main method. Place it just above the line saying @pfeil.dispose

You are the best! That works! BIG THANKS i have one little question. what can i do to disable to scroll into your bag the items if you talk with a person? i test this a few times and you can trigger items into your bag if you are talking with a person too

EDIT: after i close my game and load my savefile all items are gone

EDIT 2: two things i noticed: 1. in the common events i have one event that describe my items, would this be a problem if i have more items in the future? 2. How to erase a item? Example: i give someone a item so how to erase this item from my bag? PlayerItems.sub 1 don´t work

72ba585a1afee9978e6c3d1b81468add.png
Right, save files...I always forget that's a thing...
I also added $game_temp.message_window_showing to prevent keyboard input during messages.
Ruby:
module PlayerItems
  def self.add(id)
    $game_system._items[id] = true
    $game_variables[5] = id
  end
  
  def self.remove(id)
    $game_system._items[id] = nil
    $game_variables[5] = $game_system._items.index(true)
  end
  
  def self.has?(id)
    $game_system._items[id] == true
  end
  
  def self.update
    input_update unless $game_temp.message_window_showing
    picture_update
  end

  def self.input_update
    if $game_system._items.compact.empty?
      $game_variables[5] = -1
      return
    end
    #$game_variables[5] = $game_system._items.index(true) if $game_variables[5] < 0
    
    i = $game_variables[5]
    if Input.trigger?(Input::X)
      $game_variables[5] = $game_system._items[0...i].rindex(true) || 
                           $game_system._items[i...$game_system._items.size].rindex(true) + i
    elsif Input.trigger?(Input::Y)
      n = $game_system._items[(i+1)...$game_system._items.size].index(true)
      $game_variables[5] = n ? n + i + 1 : $game_system._items[0..i].index(true)
    end
  end
  
  def self.picture_update
    pic = case $game_variables[5]
          when 0 then 'Kalisman'
          when 1 then 'Glaskugel'
          when 2 then 'Streichhölzer'
          when 3 then 'Messer'
          when 4 then 'Amulett'
          when 5 then 'Guitar'
          when 6 then 'Gold'
          when 7 then 'Monster'
          when 8 then 'Kerze'
          when 9 then 'Flasche'
          when 10 then 'Schlüssel'
          when 11 then 'Falschgeld'
          when 12 then 'Schlüssel'
          when 13 then 'Brief'
          when 14 then 'Wrbung'
          when 15 then 'BH'
          when 16 then 'Dietrich'
          when 17 then 'Kleingeld'
          when 18 then 'Pinnadel'
          end
    
    unless pic
      $game_screen.pictures[2].erase
      return
    end
    
    $game_screen.pictures[2].show("Picture_#{pic}", 
      0, 512, 352, 100, 100, 255, 0)
  end
end

class Game_System
  attr_reader :_items
  
  alias init_player_items_later initialize
  def initialize
    init_player_items_later
    @_items = []
  end
end

Removing items is PlayerItems.remove. Look at my script again.
Code:
module PlayerItems
  def self.add(id)
This makes PlayerItems.add a valid script call. Thus the other methods below it imply...
Code:
  def self.remove(id) #=> PlayerItems.remove
  def self.has?(id) #=> PlayerItems.has?
  def self.update #=> PlayerItems.update

Your item descriptions common event shouldn't be a problem since it's not evaluating the big conditional block every frame. Though you can format it better by not having Else branches for each conditional.
1651114058295.png

Also, if you're turning ON that 'CantMove' switch during messages or cutscenes, you could just change that Conditional Branch to run the script
Code:
!$game_system.map_interpreter.running? && !$game_temp.message_window_showing
and remove that switch entirely.
Right, save files...I always forget that's a thing...
I also added $game_temp.message_window_showing to prevent keyboard input during messages.
Ruby:
module PlayerItems
  def self.add(id)
    $game_system._items[id] = true
    $game_variables[5] = id
  end
 
  def self.remove(id)
    $game_system._items[id] = nil
    $game_variables[5] = $game_system._items.index(true)
  end
 
  def self.has?(id)
    $game_system._items[id] == true
  end
 
  def self.update
    input_update unless $game_temp.message_window_showing
    picture_update
  end

  def self.input_update
    if $game_system._items.compact.empty?
      $game_variables[5] = -1
      return
    end
    #$game_variables[5] = $game_system._items.index(true) if $game_variables[5] < 0
   
    i = $game_variables[5]
    if Input.trigger?(Input::X)
      $game_variables[5] = $game_system._items[0...i].rindex(true) ||
                           $game_system._items[i...$game_system._items.size].rindex(true) + i
    elsif Input.trigger?(Input::Y)
      n = $game_system._items[(i+1)...$game_system._items.size].index(true)
      $game_variables[5] = n ? n + i + 1 : $game_system._items[0..i].index(true)
    end
  end
 
  def self.picture_update
    pic = case $game_variables[5]
          when 0 then 'Kalisman'
          when 1 then 'Glaskugel'
          when 2 then 'Streichhölzer'
          when 3 then 'Messer'
          when 4 then 'Amulett'
          when 5 then 'Guitar'
          when 6 then 'Gold'
          when 7 then 'Monster'
          when 8 then 'Kerze'
          when 9 then 'Flasche'
          when 10 then 'Schlüssel'
          when 11 then 'Falschgeld'
          when 12 then 'Schlüssel'
          when 13 then 'Brief'
          when 14 then 'Wrbung'
          when 15 then 'BH'
          when 16 then 'Dietrich'
          when 17 then 'Kleingeld'
          when 18 then 'Pinnadel'
          end
   
    unless pic
      $game_screen.pictures[2].erase
      return
    end
   
    $game_screen.pictures[2].show("Picture_#{pic}",
      0, 512, 352, 100, 100, 255, 0)
  end
end

class Game_System
  attr_reader :_items
 
  alias init_player_items_later initialize
  def initialize
    init_player_items_later
    @_items = []
  end
end

Removing items is PlayerItems.remove. Look at my script again.
Code:
module PlayerItems
  def self.add(id)
This makes PlayerItems.add a valid script call. Thus the other methods below it imply...
Code:
  def self.remove(id) #=> PlayerItems.remove
  def self.has?(id) #=> PlayerItems.has?
  def self.update #=> PlayerItems.update

Your item descriptions common event shouldn't be a problem since it's not evaluating the big conditional block every frame. Though you can format it better by not having Else branches for each conditional.
View attachment 224529
Also, if you're turning ON that 'CantMove' switch during messages or cutscenes, you could just change that Conditional Branch to run the script
Code:
!$game_system.map_interpreter.running? && !$game_temp.message_window_showing
and remove that switch entirely.

It works, thank you so much 🙂

Original thread: https://forums.rpgmakerweb.com/threads/item-problem.147105/