Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: TriangleGM on November 02, 2017, 09:02:55 pm

Title: RMXP script error involving MapInfos.rxdata [resolved]
Post by: TriangleGM on November 02, 2017, 09:02:55 pm
I am trying to create the scripts needed for non-scripters to make their own Harvest Moon style crops. I got as far the script for checking if plants are watered overnight, and I am getting an error that is well out of my league. I tried googling it, but I got nothing. I needed to cycle through every event on every map, and the only solution I found involves the rxdata, which I have avoided like the plague up to now. I don't even know a good tutorial for learning that, I just know that some people know it well, and I don't.
I am using the Self Variables (http://www.hbgames.org/forums/viewtopic.php?f=11&t=46880&start=0) from DrakoShade, as well as an original code I put together.
Here's the error:
(https://image.ibb.co/g1NX7b/error1a.jpg)
And just to be thorough, here's the "bedtime" event with the script call:
Spoiler: ShowHide
(https://image.ibb.co/hw9ZLw/error1b.jpg)


The game starts fine, but when I try to call the Overnight script, that error comes up. Here's my script:
Spoiler: ShowHide
Code: text
class Overnight

  def initialize
  @maps = []
  @farm = 1

  map_data = load_data('MapInfos.rxdata')

    for i in map_data.keys
      @maps.push(load_data(sprintf("Data/Map%03d.rxdata", i)))
    end

  end


  def water_check
    for f in 0...@maps[]

      @farm = @maps[f]
      for e in 0...@farm.events[]

        if $game_self_vaiables[[@farm, e, 1]] > 3

          if $game_self_switches[[@farm, e, "A"]] == on
            $game_self_switches[[@farm, e, "A"]] = off
            $game_self_variables[[@farm, e, 1]] += 1

          else if $game_self_switches[[@farm, e, "B"]] == off
            $game_self_variables[[@farm, e, 1]] = 3
          end
        end
      end
    end
  end
end
end

(I feel like there's one too many "ends" in there, but it won't run with any less or more.)
Self variable 1 is the main control for the crop event page.
Self switch A is used to check whether the crop has been watered.
Self Switch B checks if the crop is done growing.
If you want to look at the actual game, it can be downloaded from here: https://uploadfiles.io/xqshg (https://uploadfiles.io/xqshg)
Title: Re: RMXP script error involving MapInfos.rxdata
Post by: KK20 on November 02, 2017, 10:11:43 pm
Okay there were a lot of problems with your script so I went ahead and fixed it

module Overnight
  @@maps = {}
  # Get list of map IDs
  map_hash = load_data('Data/MapInfos.rxdata')
  map_hash.keys.each do |id|
    # Create a hash table where map ID is the key and event IDs are the value
    @@maps[id] = []
    # Load map
    map = load_data(sprintf("Data/Map%03d.rxdata", id))
    # Check every event's name on the map and add it to the list if it is soil
    map.events.keys.each do |e|
      @@maps[id].push(e) if map.events[e].name == 'Crop Soil'
    end
  end
 
  # This method is called when the player goes to sleep
  def self.water_check
    @@maps.each do |map_id, events|
      events.each do |e_id|
        # If crop event is planted and/or watered
        if $game_self_variables[[map_id, e_id, 1]] > 3
          # If crop was watered
          if $game_self_switches[[map_id, e_id, "A"]]
            # Turn switch off and increase event page
            $game_self_switches[[map_id, e_id, "A"]] = false
            $game_self_variables[[map_id, e_id, 1]] += 1
          # Crop is not finished growing
          elsif !$game_self_switches[[map_id, e_id, "B"]]
            # Goes to withered page
            $game_self_variables[[map_id, e_id, 1]] = 3
          end
        end
      end
    end
  end
end


With this, you can remove the Overnight.new in your script call. Also, there's currently a bug where if the plant is done growing (and turns on self switch B), it doesn't go to the last page. This can be resolved if you turn on self switch A again. Personally, I would event this much differently.

If you want some explanations on the scripting, like what everything is doing or why it was bugging out before, feel free to ask.
Title: Re: RMXP script error involving MapInfos.rxdata
Post by: TriangleGM on November 03, 2017, 09:04:39 am
Wow, thank you! I didn't expect anybody to put that much into helping me out with this. I know it's not a really long script, but still, this is awesome. I fixed the other things you pointed out to me too, bonus! I can see I need to study up on hash and the difference between class and module. I expect there are tutorials around for that.

To be honest, I'm probably not the best person to be making a "toolkit." I've read through "C++ For Dummies" but I am not super familiar with ruby. It's just that I've been looking for something that does this for a long time, and I always find people asking about it, so I decided to just try and make it happen myself. This is definitely an early version of my first run at it, but perhaps I'll make a topic open for suggestions on the event structure. It just has to require as little additional scripting as possible for users to make their own crops for their games, that's my main goal. They'll have to cut and paste some one-liners, but there's just no other way to make it "event based." Anyway, thanks again, this is a great!