Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Day/Night System Hicups (rpgm Xp)
DizzyFoxkit
post Mar 13 2013, 07:07 PM
Post #1



Group Icon

Group: Member
Posts: 1
Type: Musician
RM Skill: Beginner




I'm writing a Day/Night system and I'm having a major problem and a minor issue.

The major problem is that I would like for the system to turn on/off switches depending on what hour it is. I have a for loop set up to do this (It's commented out in the script to keep it from creating problems while I work.) The error that Ruby spits out is: 'Game Switches line 20: NoMethodError Occurred. Undefined method '<=' for nil:NilClass

The minor issue is simply a matter of delay. I give the developer the option to set the time according to the $current_time variable. If it is set via an event. It takes around 15 seconds for the change to occur. This leads me to two questions. Why is it taking so for the engine loop to run through and complete the code? And what are the possible ways to fix this.

I don't care if you hurt my feelings by criticizing the coding. I'm not very good at coding. I just want to get this fixed.

Script in question: http://pastebin.com/D5vngrBZ

Code In Spoiler
CODE
#------------------------------------------------------------------------------#
# Day Night Time system (DNTS) ++++++++++++++++++++++++++++++++++++++++++++++++#
# Created for BonCreationsInc +++++++++++++++++++++++++++++++++++++++++++++++++#
# Created by Xellophane +++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#------------------------------------------------------------------------------#

class Clock
  # Initialize the time objects into class variables
  # I currently don't know how to intergrate the  max_mins, and max_hours into
  # the call.
  def initialize(max_mins = 60, max_hours = 24)
    @max_mins = max_mins
    @max_hours = max_hours
    @time = 0
    @mins = $current_time[3]
    @hours = $current_time[1]
    @days = $current_time[0]
    @month = $current_time[4]
    @year = $current_time[5]
    @on_off = false
  end

  def on_off
    if @on_off = false
      @on_off = true
      return @on_off
    elsif @on_off = true
      @on_off = false
      return @on_off
    end
  end
  
  #----------------------------------------------------------------------------#
  # Clock_Tick Method                                                          #
  # Makes the time pass so long as @on_off is equal to true. While time passes #
  # It also changes the minutes, hours, and days that have passed. The for loop#
  # Changes switches on/off posistion according to what hour it is.            #
  #----------------------------------------------------------------------------#
  def clock_tick
    if @on_off = true
      @time = @time + 1
      if @time = 40
        @time = 0
        @mins = @mins + 1
      end
      if @mins > @max_mins
        @mins = 0
        @hours = @hours + 1
        # The for loop is right below
        #for i in $game_switches[i]
         # if @hours = i
          #  $game_switches[i] = true
          #else
           # $game_switches[i] = false
          #end
        #end
        # The affore mentioned for loop ends here.
      end
      if @hours > 24
        @days = @days + 1
      end
      # Everytime the @time variables ticks, the $current_time is updated
      $current_time = [@days, @hours, ":", @mins, @month, @year, @on_off]
    end
  end


This post has been edited by DizzyFoxkit: Mar 13 2013, 07:51 PM
Go to the top of the page
 
+Quote Post
   
Jens of Zanicuud
post Mar 14 2013, 11:30 AM
Post #2


Dark Jentleman
Group Icon

Group: Local Mod
Posts: 904
Type: Scripter
RM Skill: Skilled
Rev Points: 120




First off, there's a huge mistake in your script. When you use a if condition, you should use the == operator and not the = operator. The first one compares two objects, the second one makes the left object equal to the right object.

CODE
if @on_off = false
<main process>
else
<do something>
end

for example, will always perform the <main process> since a condition like if @on_off = false is always true.
To create a proper condition, you should write it this way:

CODE
if @on_off == false
<main process>
else
<do something>
end

with the == operator replacing the = operator.

As for the loop, the correct way to do that is this:
CODE
for i in 0...$game_switches.size
           if @hours == i
            $game_switches[i] = true
          else
            $game_switches[i] = false
          end
        end

what this script does: the for cycle check the whole array of switches and, if the id matches the hour, a certain switch is actived.
I suggest you limit the cycle to 24, since this script would automatically switch off any switch not corresponding to the current hour:
CODE
for i in 0...@max_hours #check a switch per hour
           if @hours == i
            $game_switches[i] = true
          else
            $game_switches[i] = false
          end
        end


Try modify it according to these hints wink.gif

I hope this can help,

Jens


__________________________
"Thorns are the rose's sweetest essence..."
-Jens of Zanicuud


Games I'm working on:
>

official website: TryAdIne eFfeCt

>

Games I worked on (mainly as a scripter):
>
(Warning: it's a 3rr3's project and it's in Italian!)


Awards

Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 22nd May 2013 - 01:39 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker