Quick question...

Started by ForeverZer0, March 24, 2010, 08:40:19 pm

Previous topic - Next topic

ForeverZer0

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!
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Aqua

Why not just do 0-512 and then subtract 255 from the result?

ForeverZer0

That would work...

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

Thanks a bunch!
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Fantasist

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*
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews