The RPG Maker Resource Kit

RMRK RPG Maker Creation => Requests => Script Request => Topic started by: heisenman on April 23, 2011, 12:42:28 AM

Title: Memorize Screen Tone
Post by: heisenman on April 23, 2011, 12:42:28 AM
Memorize Screen Tone
24 4 2011




Summary
I tried to convert ccoa's Memorize Screen Tone from XP, but alas  :V

Features Desired

Games its been in

What other scripts are you using?




Did you search?
Yes

Where did you search?

What did you search for?
Title: Re: Memorize Screen Tone
Post by: modern algebra on April 23, 2011, 12:50:25 AM
I can do this for you.
Title: Re: Memorize Screen Tone
Post by: Aurelia on April 23, 2011, 12:55:32 AM
Just one question, what are you ganna do with this script o_O? It doesn't sound like something you can't manually set
Title: Re: Memorize Screen Tone
Post by: heisenman on April 23, 2011, 01:12:25 AM
Thanks MA, I'm sure this is a easy task for you xD

Quote from: Aurelia on April 23, 2011, 12:55:32 AM
Just one question, what are you ganna do with this script o_O? It doesn't sound like something you can't manually set
It's because I have a parallel process running in every map that will change screentone when a key is pressed (kinda like night goggles), and when they key's pressed again the tone goes back to what it was before, but since not all the maps have the same tone, I cannot have it to return to just a single value.
I could do this with events, but it'll require too many conditional branches and I want to keep the parallel process as light as possible to avoid lag.
Title: Re: Memorize Screen Tone
Post by: modern algebra on April 23, 2011, 01:15:46 AM
Here:

#==============================================================================
# ** Game Map
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new instance variable - ma_memorized_tone
#==============================================================================

class Game_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_accessor :ma_memorized_tone
end

#==============================================================================
# ** Game Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new methods - memorize_screen_tone; restore_screen_tone
#==============================================================================

class Game_Interpreter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Memorize Screen Tone
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def memorize_tone
    $game_map.ma_memorized_tone = $game_map.screen.tone.clone
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Restore Screen Tone
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def restore_tone (duration = 0)
    $game_map.screen.start_tone_change ($game_map.ma_memorized_tone, duration) unless $game_map.ma_memorized_tone.nil?
  end
end


To use it, just use the following code in an evented script call to memorize it:


memorize_tone


And use the following to restore it:


restore_tone (x)


where x is the duration. So 60 would be 60 frames. If you don't include it, so just:

restore_tone

then it will do it immediately (ie 0 frames)
Title: Re: Memorize Screen Tone
Post by: ForeverZero on April 23, 2011, 01:42:23 AM
That won't save the data, though. You need to store the data in a class that gets marshalled.
Title: Re: Memorize Screen Tone
Post by: heisenman on April 23, 2011, 02:00:53 AM
Quote$game_map.screen.tone.dup
Ah, I used clone as in ccoa's version...

QuoteThat won't save the data, though. You need to store the data in a class that gets marshalled.
I don't know what it means, but I tried memorizing, changing tone, saving, F12ing, and calling the memorized tone. It worked, so I suppose the thing gets stored in the savefile.

Thanks again MA (:
Title: Re: Memorize Screen Tone
Post by: ForeverZero on April 23, 2011, 02:06:45 AM
Did you try saving the file, shutting it off, then loading the file?
I may be wrong about the whole thing, I am more of an XP person than VX.  :P
Title: Re: Memorize Screen Tone
Post by: heisenman on April 23, 2011, 02:16:29 AM
Yes, works fine (:
Title: Re: Memorize Screen Tone
Post by: modern algebra on April 23, 2011, 02:17:11 AM
No, he's right that the script doesn't work. Well, not quite for those reasons - the class will get marshalled since they are always saved to variables within classes that do get marshalled (Game_Event; Game_CommonEvent; Game_Map). But making it an instance variable was silly since it won't work through any of the other interpreters - IE you couldn't restore it or memorize it through any parallel process events or common events or even child interpreters. I should have either put it in a class like Game_Map or made it a class variable.

I've changed it to a class variable since that was easier. Grab it again from the previous post.

But yeah; thanks for the catch ForeverZero - I wouldn't have given that choice a second thought if you hadn't popped in. I definitely should have been smarter about it. Also, putting it in another class like Game_Map would probably be smarter than using a class variable, but adding three extra @s was slightly faster and I'm lazy.

Also, @heisenman - clone would have worked too. They're the same method except clone is a more complete copy as it includes freeze status and singleton methods. Are you sure that was that the only difference?
Title: Re: Memorize Screen Tone
Post by: heisenman on April 23, 2011, 02:35:52 AM
Before I make myself sound sillier than I actually am, I did try if it worked but not on my parallel process, just on some dummy events :tpg:

Quote@heisenman - clone would have worked too. They're the same method except clone is a more complete copy as it includes freeze status and singleton methods. Are you sure that was that the only difference?
Nope, that wasn't the only difference at all, the reason why it wasn't working is surely because I copypasted things at random out of desperation.

EDIT: After quitting, loading and calling the common event again.

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg268.imageshack.us%2Fimg268%2F5889%2F37690463.png&hash=05dc3dae160d63a062fc325c5958b5454915bff5)
Title: Re: Memorize Screen Tone
Post by: modern algebra on April 23, 2011, 02:52:43 AM
Alright, I fixed it this time for real and wasn't as lazy. I replaced it in the first post.

I knew that class variables weren't marshalled; it didn't make any sense. I had tested it using F12 though and it worked, so I stupidly assumed that I had been wrong. Dumb me :)
Title: Re: Memorize Screen Tone
Post by: heisenman on April 23, 2011, 03:15:28 AM
All right, the third time is the lucky one.
It works both ways:

1) Open > Use goggles to change tone > Save > Quit > Load > Use goggles again > Just fine. (It crashed here before)
2) Open > Use goggles to change tone> Use goggles to resore tone > Save > Quit > Load > Use goggles again > Just fine.

I cannot think of other ways to test if works correctly. If I run into other problems I'll come back begging for assistance.


Thanks MA for the patience, and thanks ForeverZero for helping (: