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.

A Few Basic Questions

What is the difference between a module and a class?

I've noticed you don't need an initialize method in a module...Why is this?

Is it harder to script one than the other?
Also, how would you go about checking if a certain event's conditions such as switch1,switch2,variable are valid, and the event pages and such?
 
I've noticed you don't need an initialize method in a module...Why is this?
Classes does not require initialize methods either. This is just often used because it is automatically run when instanced.

Now let me break this down to a quick context. Modules are collections of methods and constants. However, it is possible to build classes inside modules. To see what I mean, check the RGSS help file for the RPG module with all its built classes.

Now, constants in modules can be understood by looking at the Input module in the help file. Here you have constants defined, such as C and B (Input::C, Input::B).

As I said, modules can hold classes, classes cannot hold modules.

Now for the event page-check, events have a page array. The condition class is defined in the spoiler below.
Code:
module RPG
  class Event
    class Page
      class Condition
        def initialize
          @switch1_valid = false
          @switch2_valid = false
          @variable_valid = false
          @self_switch_valid = false
          @switch1_id = 1
          @switch2_id = 1
          @variable_id = 1
          @variable_value = 0
          @self_switch_ch = "A"
        end
        attr_accessor :switch1_valid
        attr_accessor :switch2_valid
        attr_accessor :variable_valid
        attr_accessor :self_switch_valid
        attr_accessor :switch1_id
        attr_accessor :switch2_id
        attr_accessor :variable_id
        attr_accessor :variable_value
        attr_accessor :self_switch_ch
      end
    end
  end
end
As you see here, all the switches and other conditions are perfectly shown as accessors. The code found in Game_Event for checking this before 'start' is initiated, is as follows:
Code:
    unless @erased
      # Check in order of large event pages
      for page in @event.pages.reverse
        # Make possible referrence for event condition with c
        c = page.condition
        # Switch 1 condition confirmation
        if c.switch1_valid
          if $game_switches[c.switch1_id] == false
            next
          end
        end
        # Switch 2 condition confirmation
        if c.switch2_valid
          if $game_switches[c.switch2_id] == false
            next
          end
        end
        # Variable condition confirmation
        if c.variable_valid
          if $game_variables[c.variable_id] < c.variable_value
            next
          end
        end
        # Self switch condition confirmation
        if c.self_switch_valid
          key = [@map_id, @event.id, c.self_switch_ch]
          if $game_self_switches[key] != true
            next
          end
        end
        # Set local variable: new_page
        new_page = page
        # Remove loop
        break
      end
    end
This code goes through all the event pages from the last to first (if you have 5 it starts at 5 and ends at 1) and checks if the conditions are met. This means, if page 5's conditions are met, it runs that page.
You would basically want to create a new method with this inside that returns true or false if everything is met or not. So for instance you would have the block named 'conditions_met?'. Using the code for conditional branches or in a script:
Code:
$game_map.events[id_here].conditions_met?
Or something like that.

Hope this was of any help.
 

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