Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: Ryex on July 26, 2008, 10:20:03 am

Title: [Resolved]Script Not working
Post by: Ryex on July 26, 2008, 10:20:03 am
CODE:

class Game_Event
  attr_reader :id
end

module CP
 
  def self.first_event_comment(event, comment)
    return (event.list.is_a?(Array) && event.list[0].code == 108 &&
         event.list[0].parameters[0] == comment)
  end
 
  def self.find_first_event(dir = $game_player.direction, range = 1, string = '')
    case dir
    when 2
      (1..range).each {|i| $game_map.events.each_value {|event|
      if event.x == $game_player.x && event.y == $game_player.y + i &&
          CP.first_event_comment(event, string)
        return event.id
      end}}
    when 4
      (1..range).each {|i| $game_map.events.each_value {|event|
      if event.y == $game_player.y && event.x == $game_player.x - i &&
          CP.first_event_comment(event, string)
        return event.id
      end}}
    when 6
      (1..range).each {|i| $game_map.events.each_value {|event|
      if event.y == $game_player.y && event.x == $game_player.x + i &&
          CP.first_event_comment(event, string)
        return event.id
      end}}
    when 8
      (1..range).each {|i| $game_map.events.each_value {|event|
      if event.x == $game_player.x && event.y == $game_player.y - i &&
          CP.first_event_comment(event, string)
        return event.id
      end}}
    end
    return 0
  end
 
  def self.trigger(string, range, switch)
    event_id = self.find_first_event($game_player.direction, range, string)
    return if event_id == 0
    key = [$game_map.map_id, event_id, switch]
    $game_self_switches[key] = true
  end
 
end



Purpose

The Above Code dose the fallowing. when called like this
CP.trigger('string', range, switch)

It checks in fount of the player and finds the first event that has comment 'string' in the first line on the currently running page that is within range then it takes that event and switches self switch switch (it can be 0, 1, 2, 3, for a, b, c, or d) to on

Problem

heres the problem I made a common event that calls the script like this

CP.trigger('hi', 4, 0)


I then made a skill that calls that common event and gave the skill menu use and gave the fighter class access to it at lv 1
then I made an event in the first page I made a comment on the first line that said hi and on the second page I Required self switch a to be on and set it to auto run and made it do several things like text and battle processing.  but when you used the skill nothing happened. I used the 'p' command to print things to test if things were working and they were the problem lies in flipping the self switch
and neither I nor Blizzard knows what going wrong
Title: Re: Script Not Wroking
Post by: Blizzard on July 26, 2008, 10:27:34 am
Of course I don't know what's going on since I wrote it out of my head. What do you expect? -_-
Title: Re: Script Not Wroking
Post by: Ryex on July 26, 2008, 03:50:05 pm
bliz even when you write something out of your head its good thought most of the code was already there you just reorganized it and optimized it
Title: Re: Script Not Wroking
Post by: Blizzard on July 26, 2008, 09:41:42 pm
I mean that I found bugs and fixed them just by looking through the code. There could be another not so obvious bug.
Title: Re: Script Not Wroking
Post by: Ryex on July 27, 2008, 03:41:30 pm
is it possible to call the interpreter's method for changing selfswichs instead of making our own?
Title: Re: Script Not Wroking
Post by: Blizzard on July 27, 2008, 04:07:52 pm
You still have to code that call. In the end it's the same.
Title: Re: Script Not Wroking
Post by: Ryex on July 29, 2008, 10:02:24 am
I FIXED IT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  :haha: :haha: :haha: :haha: :D 8)

I desired to inspect the interrupter further so I put an extra line the said
p @paramertes[0].to_s


jest before it made the key

then I mad an event that just changed the self switch to a. it turns out that the  window popped up with "A"

so you were wrong it is not 0, 1, 2, 3 for the self switches. instead it is "A", "B", "C", "D"

so when you call it you have to put the self switch in a capital quoted string

oh and this this is necessary right after changing the switch

$game_map.need_refresh = true


I tried it with out and it did not work


so here is the whole completed code that works

class Game_Event
  attr_reader :id
end

module CP
 
  def self.first_event_comment(event, comment)
    return (event.list.is_a?(Array) && event.list[0].code == 108 &&
         event.list[0].parameters[0] == comment)
  end
 
  def self.find_first_event(dir = $game_player.direction, range = 1, string = '')
    case dir
    when 2
      (1..range).each {|i| $game_map.events.each_value {|event|
      if event.x == $game_player.x && event.y == $game_player.y + i &&
          CP.first_event_comment(event, string)
        return event.id
      end}}
    when 4
      (1..range).each {|i| $game_map.events.each_value {|event|
      if event.y == $game_player.y && event.x == $game_player.x - i &&
          CP.first_event_comment(event, string)
        return event.id
      end}}
    when 6
      (1..range).each {|i| $game_map.events.each_value {|event|
      if event.y == $game_player.y && event.x == $game_player.x + i &&
          CP.first_event_comment(event, string)
        return event.id
      end}}
    when 8
      (1..range).each {|i| $game_map.events.each_value {|event|
      if event.x == $game_player.x && event.y == $game_player.y - i &&
          CP.first_event_comment(event, string)
        return event.id
      end}}
    end
    return 0
  end
 
  def self.trigger(string, range, switch)
    event_id = self.find_first_event($game_player.direction, range, string)
    return if event_id == 0
    key = [$game_map.map_id, event_id, switch]
    $game_self_switches[key] = true
    $game_map.need_refresh = true
  end
 
end


you call it like this

CP.trigger('string', range, "switch")
Title: Re: [Resolved]Script Not working
Post by: Fantasist on July 29, 2008, 11:08:07 am
Yay, more energy to you then :D
Title: Re: [Resolved]Script Not working
Post by: Ryex on July 31, 2008, 12:21:32 pm
yay now i have three!! wait some one must of downed me at some point because I used to have three anyway...  any way YAY POWER UP
Title: Re: [Resolved]Script Not working
Post by: Blizzard on July 31, 2008, 07:00:19 pm
LMAO! I never would have thought. BTW, you can use ' instead of ". Strings with ' are processed a bit faster than with ".
Title: Re: [Resolved]Script Not working
Post by: Ryex on July 31, 2008, 07:19:10 pm
i knew that...  just slipped my mind...