Self Switch Reseter

I still can't get why this happens...

1642349581872.png


Usually it's some event... but I literally disabled all of them (with an unactivated condition, I'm assuming the script doesn't still check events that can't even trigger?) - so I should have nothing that activates when the player goes on this map... and, needless to say, there's no <resetss: 0abcd> anywhere, either. Why does it keep referring to that line 50? Which has
bob = @page.reset_ss if bob == "" or bob.include? "0"
please give a link to the website where you got the reset self switch script from.
no one can help you without a link to that website
It's not very long:
#--------------------------------# # Dramatic Lightning Co Presents: # Self Switch Reseter #--------------------------------# # You can reset your Event's Self Switches with this script! # Create a Comment in the first line of your Event page and # place <resetss: 0abcd> there. abcd are the letters of the # self switch you want to reset. #--------------------------------# # By default, you only need to place the notetag in the first # page and it'll reset the self switches regardless of what # page you're on. You can put 0 (zero) in the notetag so that it'll # only affect the first page. Alternatively, you can place the # notetags in each other page. #--------------------------------# module DL module Renew Regex = /<resetss:\s*(\w+)\s*>/i end end module RPG class Event::page def reset_ss bob = "" @list.each {|cmd| if cmd.code == 108 && res = cmd.parameters[0].match(DL::Renew::Regex) bob = res[1].to_s end } return bob end end end class Game_Event < Game_Character alias dl_renew_initialize initialize def initialize(map_id, event) dl_renew_initialize(map_id, event) renew_self(map_id, event) refresh end def renew_self(map_id, event) bob = "" bob = @event.pages[0].reset_ss if @event.pages[0] bob = @page.reset_ss if bob == "" or bob.include? "0" $game_self_switches[[map_id, event.id, "A"]] = false if bob.include? "a" $game_self_switches[[map_id, event.id, "B"]] = false if bob.include? "b" $game_self_switches[[map_id, event.id, "C"]] = false if bob.include? "c" $game_self_switches[[map_id, event.id, "D"]] = false if bob.include? "d" end end
It's not very long:
Regardless you need to use a code block when pasting code into your post.
There actually seems to be an error in the code you posted as well.
It took a while to figure out how to use the script.
using <reset_ss: 0abcd> pretty makes the code useless from what I can tell.
Only works on page 0? If you self switch A on then your on page 1. How will the code even work then.
I did a test and put <reset_ss: abcd> on page 2 of an event.
It did nothing until I changed maps. So when reloading a map is when the script works.
Then it makes sense for the 0 to come into affect. Page 0 is read and all self switches are turned off.

the P in Event:: Page was not capitalized
Ruby:
#--------------------------------#
# Dramatic Lightning Co Presents:
# Self Switch Reseter
#--------------------------------#
# You can reset your Event's Self Switches with this script!
# Create a Comment in the first line of your Event page and
# place <resetss: 0abcd> there.  abcd are the letters of the
# self switch you want to reset.
#--------------------------------#
# By default, you only need to place the notetag in the first
# page and it'll reset the self switches regardless of what
# page you're on.  You can put 0 (zero) in the notetag so that it'll
# only affect the first page.  Alternatively, you can place the
# notetags in each other page.
#--------------------------------#


module DL
  module Renew
   Regex = /<resetss:\s*(\w+)\s*>/i
  end
end

module RPG
  class Event::Page

   def reset_ss
     bob = ""
     @list.each {|cmd|
       if cmd.code == 108 && res = cmd.parameters[0].match(DL::Renew::Regex)
         bob = res[1].to_s
       end
     }
     return bob
   end
  end
end

class Game_Event < Game_Character
  alias dl_renew_initialize initialize
  def initialize(map_id, event)
   dl_renew_initialize(map_id, event)
   renew_self(map_id, event)
   refresh
  end

   def renew_self(map_id, event)
     bob = ""
     bob = @event.pages[0].reset_ss  if @event.pages[0]
     bob = @page.reset_ss if bob == "" or bob.include? "0"
 
     $game_self_switches[[map_id, event.id, "A"]] = false if bob.include? "a"
     $game_self_switches[[map_id, event.id, "B"]] = false if bob.include? "b"
     $game_self_switches[[map_id, event.id, "C"]] = false if bob.include? "c"
     $game_self_switches[[map_id, event.id, "D"]] = false if bob.include? "d"
   end
 
end
Ignore the uncapitalized p really, it was something I ended up changing before using the code tag because the forum interpreted it as a tongue-in-cheek emoji... other than that though, what could I do? Not sure I understood what I can change with the first paragraph.
@Roninator2
I actually explained what the bug was already.

reset_ss: is a method.
"undefined method reset_ss for nil:nilclass" is the error

think!
how can "reset_ss" be undefined, if you just pasted it from the code where it is defined?
if page.reset_ss is undefined, that means page is undefined.
where is that page coming from!?
trace the code! that's how you find errors!

Code:
 def renew_self(map_id, event)
     bob = ""
     bob = @event.pages[0].reset_ss  if @event.pages[0]
     bob = @page.reset_ss if bob == "" or bob.include? "0"
     $game_self_switches[[map_id, event.id, "A"]] = false if bob.include? "a"
     $game_self_switches[[map_id, event.id, "B"]] = false if bob.include? "b"
     $game_self_switches[[map_id, event.id, "C"]] = false if bob.include? "c"
     $game_self_switches[[map_id, event.id, "D"]] = false if bob.include? "d"
  end

this
Code:
bob = @event.pages[0].reset_ss  if @event.pages[0]    
bob = @page.reset_ss if bob == "" or bob.include? "0"
includes a reference to the error.
THIS, is problematic to the analysis of the problem.
so, make THIS, something LESS problematic:

Code:
page = @event.pages[0]
if page != nil
 bob = @event.pages[0].reset_ss
 if bob == "" or bob.include? "0"
  bob = @page.reset_ss
 end
end

STRUCTURE.
the code can't go where you don't let it.
Eh, my personal fix would be like this to replace line 50
Code:
bob = @page.reset_ss if @page && (bob == "" || bob.include? "0")
Eh, my personal fix would be like this to replace line 50
Game_PRH1Y5LTmb.png
@TheoAllen there is a priority for running those, that I'm not sure it will affect the thing.
the plain basic structure is fail-proof.
it's the OG thing, and you can always rely on it working as intended.
@Nereid why exactly do you need this script? Wouldn't it be easier to manually reset the self switch? Or use a script that allows you to do the same with a short script call?
A script that's even shorter?
@Nereid
there is one question you have to answer:

what do you want that script to do?

If you cannot answer that question, then the solution is to remove that script because you don't need it.
I'm using it to respawn enemies. What's strange, though, is that the error occurs where there are no such events.
it was something I ended up changing before using the code tag because the forum interpreted it as a tongue-in-cheek emoji.
That's why you use code tags like I did.
I'm assuming the script doesn't still check events that can't even trigger?
It looks like it only checks the first page and the current page. (if not page 0)
I actually explained what the bug was already.
Didn't catch that.
the error occurs where there are no such events.
What do you mean. No events with the comment? That doesn't matter if (as KK20 said) there are events that do not have a valid page condition.

It's like this. You have an event -> it only has one page -> it's on a condition that switch 3 is on - > switch 3 is off -> event does not have a valid page.

Insert this above the error line.
return if @page.nil?
The error will not show up again. *tested and confirmed with getting the error and this fixes it.
Yep, seems to have fixed it, thanks.

Original thread: https://forums.rpgmakerweb.com/threads/self-switch-reseter.144017/