Chaos Project

RPG Maker => RPG Maker Scripts => Topic started by: ForeverZer0 on March 24, 2010, 08:40:19 pm

Title: Quick question...
Post by: ForeverZer0 on March 24, 2010, 08:40:19 pm
Does anybody know an easy way to have a variable loop through a range between a negative number and a positive number.

For example, for my screen test script, to keep the allowable range for the screen tone I have to use this:

    case @window_screen.index
    when 0 # Red Tone
      if Input.trigger?(Input::RIGHT)
        $game_screen.tone.red += 1
        $game_screen.tone.red = 255 if $game_screen.tone.red >= 255
      elsif Input.trigger?(Input::LEFT)
        $game_screen.tone.red -= 1
        $game_screen.tone.red = -255 if $game_screen.tone.red <= -255
      elsif Input.repeat?(Input::RIGHT)
        $game_screen.tone.red += 5
        $game_screen.tone.red = 255 if $game_screen.tone.red >= 255
      elsif Input.repeat?(Input::LEFT)
        $game_screen.tone.red -= 5
        $game_screen.tone.red = -255 if $game_screen.tone.red <= -255
      end


I want to use something that works more like this:


    when 4 # Weather Type
      if Input.trigger?(Input::RIGHT)
        $game_screen.weather_type = ($game_screen.weather_type += 1) % Z::Weather_Types
      elsif Input.trigger?(Input::LEFT)
        $game_screen.weather_type = ($game_screen.weather_type -= 1) % Z::Weather_Types
      end


This is much shorter and easier, but I want it to work with a range between -255 and 255.

Any suggestions would be greatly appreciated. Thanks!
Title: Re: Quick question...
Post by: Aqua on March 24, 2010, 08:51:51 pm
Why not just do 0-512 and then subtract 255 from the result?
Title: Re: Quick question...
Post by: ForeverZer0 on March 24, 2010, 09:10:26 pm
That would work...

I don't know why I didn't think of that..

Thanks a bunch!
Title: Re: Quick question...
Post by: Fantasist on March 25, 2010, 07:20:24 am
Quote from: Elite Four Aqua on March 24, 2010, 08:51:51 pm
Why not just do 0-512 and then subtract 255 from the result?

Simplicity ftw!  :rockit: *levels up*

But then, I don't see anything wrong with what you (ForeverZero) did in the first place.

Also, quote from Tone in the RMXP's help file:

Quote
red
The red balance adjustment value (-255 to 255). Values out of range are automatically corrected.


You basically don't need to correct at all :) I feel like leveling up the RMXP help file. Oh well: *pseudo-levelup RMXP help file*