public

Rpg Maker Developers Group

Simple enough for a child, powerful enough for a developer

2 Followers

Need last minute help with brother's Light Puzzle script

BMM_Archive · July 15, 2026

Preserved forum archive. This topic stores the original first post and locally mirrored RPG Maker Web attachments when available. It is posted by the BMMPlay archive account, not by the original creator.

Original Source

  • Original title: Need last minute help with brother's Light Puzzle script
  • Original author: Valkymie
  • Original date: August 7, 2015
  • Source thread: https://forums.rpgmakerweb.com/threads/need-last-minute-help-with-brothers-light-puzzle-script.43355/
  • Source forum path: Game Development Engines > Ruby Game System (RGSS) Scripts > RGSSx Script Support

Summary

First off, the script in question: Also, Demo Spoiler module Light_Puzzle  def self.initialize()    # This maps the event IDs to the physical location indices used by the code    # 1st ID -- 2nd ID -- 3rd ID    #    |         |         |    # 4th ID -- 5th ID -- 6th ID    #    |         |         |    # 7th ID -- 8th ID -- 9th ID    @mirror_id_mapping=[1,2,3,4,5,6,7,8,9]     ...

Archived First Post

First off, the script in question:

Also, Demo

module Light_Puzzle  def self.initialize()    # This maps the event IDs to the physical location indices used by the code    # 1st ID -- 2nd ID -- 3rd ID    #    |         |         |    # 4th ID -- 5th ID -- 6th ID    #    |         |         |    # 7th ID -- 8th ID -- 9th ID    @mirror_id_mapping=[1,2,3,4,5,6,7,8,9]        # This maps to the light beam IDs. Each group of 4 represents the four    # beams coming out of the mirror, e.g. the first set of 4 is for the     # first mirror. The order goes South, West, East, North (2,4,6,8)    @light_id_mapping=[[36,18,20,19],[21,20,13,0],[15,13,23,22],[34,35,37,36],[29,37,28,21],[27,28,24,15],[33,11,30,34],[31,30,26,29],[32,26,25,27]]        # This represents the initial prisms inserted into the puzzle upon map load    # 0 - No prism    # 1 - White prism    # 2 - Red prism    # 3 - Yellow prism    # 4 - Blue prism    # E.g. a 1 in the 2nd slot means the top-center mirror has a white prism    # to start.    @prism_index=[0,1,0,0,0,0,4,0,0]    cnt=0    for i in @prism_index      self.add_prism(cnt,i)      cnt+=1    end        # This represents the color of the beam as it traverses the puzzle.    # The order is White, Red, Yellow, Blue    @current_beam_color=[0,0,0,0]        # This is the event ID of the common event called when the puzzle is finished.    @win_event_id = 20        self.evaluate(1,nil,nil)  end    # This is the only function call you need.  # event_id - ID of the event you want to change (should be the mirror ID)  # new_dir  - New direction of the mirror, (2,4,6,8). Use nil keep the current  #            direction  # prism    - New prism, 0 through 4. 0 removes the prism. Use nil the keep the  #            current prism in place.  def self.evaluate(event_id,new_dir,prism)    mirror_index = @mirror_id_mapping.index(event_id)    self.reset_light()    unless new_dir == nil then      self.set_direction(mirror_index,new_dir)    end    unless prism == nil then      self.add_prism(mirror_index,prism)    end    cur_mirror = 1    prev_dir = 2    begin      mirror_id = self.get_mirror_id(cur_mirror)      dir = $game_map.events[mirror_id].direction      case      when cur_mirror == 6 then cur_mirror = -2      when dir == prev_dir then cur_mirror = -1      when dir == 2 && prev_dir == 8 then cur_mirror = -1      when dir == 4 && prev_dir == 6 then cur_mirror = -1      when dir == 6 && prev_dir == 4 then cur_mirror = -1      when dir == 8 && prev_dir == 2 then cur_mirror = -1      else          @light_index[cur_mirror] = dir          light_id = self.get_light_id(cur_mirror)          self.add_color(@prism_index[cur_mirror])          $game_map.events[light_id].transparent = false          # Uncomment these lines when you're ready.                     #color = self.get_color_index()           #c_index=$game_map.events[light_id].character_index           #$game_map.events[light_id].set_graphic(color,c_index)          cur_mirror = self.get_next_mirror(cur_mirror,dir)          prev_dir = dir      end    end while cur_mirror >= 0    if cur_mirror == -2  then      $game_temp.reserve_common_event(@win_event_id)    end  end    def self.get_next_mirror(cur_mirror,dir)    case dir    when 2 then self.get_mirror_down(cur_mirror)    when 4 then self.get_mirror_left(cur_mirror)    when 6 then self.get_mirror_right(cur_mirror)    when 8 then self.get_mirror_up(cur_mirror)    end  end  def self.add_prism(cur_mirror,prism)    @prism_index[cur_mirror]=prism    mirror_id = self.get_mirror_id(cur_mirror)    index = $game_map.events[mirror_id].character_index    case prism    when 0 then $game_map.events[mirror_id].set_graphic("!$SMaltars",index)    when 1 then $game_map.events[mirror_id].set_graphic("!$SMaltersCWHITE",index)    when 2 then $game_map.events[mirror_id].set_graphic("!$SMaltersCRED",index)    when 3 then $game_map.events[mirror_id].set_graphic("!$SMaltersCYELLOW",index)    when 4 then $game_map.events[mirror_id].set_graphic("!$SMaltersCBLUE",index)    end  end  def self.set_direction(mirror,direction)    mirror_id = self.get_mirror_id(mirror)    $game_map.events[mirror_id].direction = direction  end  def self.get_mirror_left(mirror)    case mirror    when 1 then 0    when 2 then 1    when 4 then 3    when 5 then 4    when 7 then 6    when 8 then 7    else -1    end  end  def self.get_mirror_right(mirror)    case mirror    when 0 then 1    when 1 then 2    when 3 then 4    when 4 then 5    when 6 then 7    when 7 then 8    else -1    end  end    def self.get_mirror_up(mirror)    case mirror    when 3 then 0    when 4 then 1    when 5 then 2    when 6 then 3    when 7 then 4    when 8 then 5    else -1    end  end  def self.get_mirror_down(mirror)    case mirror    when 0 then 3    when 1 then 4    when 2 then 5    when 3 then 6    when 4 then 7    when 5 then 8    else -1    end  end  def self.reset_light()    @light_index=[0,0,0,0,0,0,0,0,0]    @light_id_mapping.each do |sub_array|      sub_array.each do |id|        if id != 0 then          $game_map.events[id].transparent = true        end      end    end    end  def self.get_light_id(mirror)    dir = @light_index[mirror]    index = dir/2-1    return @light_id_mapping[mirror][index]  end  def self.get_mirror_id(index)     @mirror_id_mapping[index]  end  def self.add_color(prism)    @current_beam_color[prism-1]+=1  end  def self.get_color_index()    w = @current_beam_color[0]    r = @current_beam_color[1]    y = @current_beam_color[2]    b = @current_beam_color[3]    case    # Copy and paste as many "whens" as you need. Replace with actual graphic    # names (in quotes)    when w==1 && r==0 && y==0 && b==0 then "!$WhiteH"    when w==1 && r==1 && y==0 && b==0 then "!$RedH"    when w==1 && r==0 && y==1 && b==0 then "!$YellowH"    when w==1 && r==0 && y==0 && b==1 then "!$BlueH"    when w==1 && r==1 && y==1 && b==0 then "!$OrangeH"    when w==1 && r==0 && y==1 && b==1 then "!$GreenH"    when w==1 && r==1 && y==0 && b==1 then "!$VioletH"    when w==1 && r==1 && y==1 && b==1 then "!$BrownH"    when w==1 && r==2 && y==0 && b==0 then "!$RedH"    when w==1 && r==0 && y==2 && b==0 then "!$YellowH"    when w==1 && r==0 && y==0 && b==2 then "!$BlueH"    when w==1 && r==2 && y==1 && b==0 then "!$RedOrangeH"    when w==1 && r==2 && y==0 && b==1 then "!$RedVioletH"    when w==1 && r==1 && y==2 && b==0 then "!$YellowOrangeH"    when w==1 && r==1 && y==0 && b==2 then "!$BlueVioletH"    when w==1 && r==0 && y==1 && b==2 then "!$BlueGreenH"    when w==1 && r==0 && y==2 && b==1 then "!$YellowGreenH"    when w==1 && r==1 && y==2 && b==1 then "!$BrownH"    when w==1 && r==2 && y==1 && b==1 then "!$BrownH"    when w==1 && r==1 && y==1 && b==2 then "!$BrownH"    when w==1 && r==2 && y==2 && b==0 then "!$OrangeH"    when w==1 && r==2 && y==0 && b==2 then "!$VioletH"    when w==1 && r==0 && y==2 && b==2 then "!$GreenH"    when w==1 && r==1 && y==0 && b==3 then "!$BlueVioletH"    when w==1 && r==3 && y==0 && b==1 then "!$RedVioletH"    when w==1 && r==3 && y==1 && b==0 then "!$RedOrangeH"    when w==1 && r==1 && y==3 && b==0 then "!$YellowOrangeH"    when w==1 && r==0 && y==1 && b==3 then "!$BlueGreenH"    when w==1 && r==0 && y==3 && b==1 then "!$YellowGreenH"    end  end  end
tldr; Monochrome version of puzzle works fine, adding color ruins everything.

Now then, for the last puzzle in my game I wanted it to be a light puzzle. It's the only thing I have left to work on for my game, but since I cant get it to work yet, I made a back-up version that just skips this part of the game...

My brother has work, so he can't really help me anymore before the deadline for IGMC2015

How it goes is that:

There are 9 mirrors you can rotate, add a color prism to, or remove a color prism from. That part pretty much works.

When the mirrors are lined up a certain way, a path of light will shine (another event) The mirrors have to "make" a 90 degree angle. So a path of light can't shine through the back of another mirror so to speak.

Here's an example of a "winning" path.

x    x---x

           |

x    x---x

      |

x---x    x

Which is from top-middle to bottom-left like so. (As far as I'm concerned there's only one other path that works)

But as you can see, there are no "3-in-a-row" straight lines of light beams

THE PROBLEM: 

is when it comes to figuring out the colors of the light beams, and whether the graphic will be horizontal or vertical. Let's start with the latter.

At the bottom of the script is where my brother told me to put all the combinations of what prisms are set in the mirrors, and what color beam that will produce, the first (top middle) mirror having a white prism in it to start, and the last (bottom left) has a blue prism in it, but I believe he said the script doesn't "count" that last mirror's prism (its prism also isn't counted in the when calls at the end of the script).

So for example, if you have a path set up like diagram above, putting a red prism in the top-right will make the light beam it produces below it red. Put a blue prism in that next mirror, the next light beam will be violet, put another blue in the next one, the beam will be blue-violet, etc. (player has 3 red, blue, and yellow prisms each)

However, I can't figure out how to make the script check which direction the mirror is facing. Because if it's up or down (2 or 8??), it needs to use the vertical light graphics (ends in V instead of H)

My brother via skype said the following:

It will be hard to explain via text

The light ID index stores the positions indirectly. You know if it's first or last in the group of 4 that it's vertical. Try to use that to know whether it's vertical.

I can't write the code or anything but that's the way I'd do it

Actually use dir the mirror direction

I made it so the next beam of light to draw is in the mirrors direction

Change the get color index function to accept dir as a parameter, and use that to determine the orientation
So idk if it's just me being tired or stupid but I don't know how to actually do it and i dont want to keep pestering him while he's at work.

So doing that should fix the problem with the colored light beams all showing up as horizontal.

 

The Other Problem:

is the deal with the color itself. There's a section in the script that says "uncomment these lines when you're ready", which are commented in the script I posted. Lines 75-77 in rpg maker

IF I keep them commented, the lights remain default white, and the puzzle is complete-able in its monochrome state, but it would mean not using the colored prisms at all.

When I uncomment these commands, and try to re-create the path in that diagram I made, the first light beam is white as it should be, but the second one is blue despite there not being any prism in that second (top right) mirror (is this another side effect of not being able to use the vertical beam images yet?) I even tried removing the blue crystal from the last mirror, and the " && color == "!$BlueViolet": from line 62 (defining that you need the last beam to be that color in order to succeed), but it was still showing up with a blue horizontal beam instead of a white vertical one

and then, when I try to move the next mirror (middle-right), I get an error that says:
Script: 'Game_CharacterBase' line 246: NoMethodError occurred.

undefined method `[]' for nil:NilClass
 

Idk if that's a problem in the script or if it's a problem in the event itself.

Also, here's screenshot examples of what the mirror event pages look like, just in case.


[IMG]http://i.imgur.com/6AT3Raj.png[/IMG]

[IMG]http://i.imgur.com/ixGn4Lc.png[/IMG]

[IMG]http://i.imgur.com/UVCzp3O.png[/IMG]

[IMG]http://i.imgur.com/ouHWilt.png[/IMG]

[IMG]http://i.imgur.com/CuQEnu6.png[/IMG]



Personally I don't think it's an issue with the events but hey what do I know.

 

So basically yeah, I just can't get the colored beams to work right

If anyone can help me before the contest ends, that would be hella lovely

 

Thank you so much in advance!

 

P.S. if you need more information, let me know!

Downloads / Referenced Files

Log in to download

Log in, then follow the RPG Maker Developers Group to see these download links.

Log in to download
Creator Claims / Removal

If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.

#039#color#c_index#rpg-maker-archive#rgss-support

Replies (0)

No replies yet.

0 replies 1 view

Log in to reply.

User Avatar