RMMZ I use Javascript to set up screen tint. How do I add a duration?

dm604

Veteran
Veteran
Joined
Sep 18, 2021
Messages
41
Reaction score
14
First Language
English
Primarily Uses
RMMZ
Hi:
Here is the code:


$gameScreen.startTint([$gameVariables.value(213), $gameVariables.value(214), $gameVariables.value(215), $gameVariables.value(216)], 1)

My question is, how do I add the duration like the function that comes within the editor?

Thank you.
 

Attachments

  • Annotation 2021-09-22 104804.png
    Annotation 2021-09-22 104804.png
    60.5 KB · Views: 2

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
57
Reaction score
28
First Language
English
Primarily Uses
RMMZ
That "1" that you have in the very end is the duration parameter.

The function goes like this:

JavaScript:
let rgbg = [200,0,0,0]
let duration = 300 // the tint will take 300 frames to set in

$gameScreen.startTint(
   rgbg,
   duration
)
 

dm604

Veteran
Veteran
Joined
Sep 18, 2021
Messages
41
Reaction score
14
First Language
English
Primarily Uses
RMMZ
That "1" that you have in the very end is the duration parameter.

The function goes like this:

JavaScript:
let rgbg = [200,0,0,0]
let duration = 300 // the tint will take 300 frames to set in

$gameScreen.startTint(
   rgbg,
   duration
)

Thank you!
Since I use 4 variables (RGBG) to store each hue, so I guess I can use:

$gameScreen.startTint([$gameVariables.value(213), $gameVariables.value(214), $gameVariables.value(215), $gameVariables.value(216)], 300)
 

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
57
Reaction score
28
First Language
English
Primarily Uses
RMMZ
@dm604

Using RPGM's variables inside script calls might become burdensome maintenance-wise.

For example, if you change the red tint color from variable 213 to 1001 then you have to change every single script where that variable is mentioned. But there is a better way.

First, you run an initialization event where you link, only once, variable 213 to a script variable. And then in all your script calls you use the script variable and not the RPGM variable. This is called separation of concepts.

Your autorun initialization event that runs once on startup and links every RPGM variable against a respective script variable:

001.png

Your actual script call event:

002.png

Now, if you change your mind about using 213 and start using 1001 instead, all you need to do is change what that variable is linked to in the initialization event.
 

dm604

Veteran
Veteran
Joined
Sep 18, 2021
Messages
41
Reaction score
14
First Language
English
Primarily Uses
RMMZ
@dm604

Using RPGM's variables inside script calls might become burdensome maintenance-wise.

For example, if you change the red tint color from variable 213 to 1001 then you have to change every single script where that variable is mentioned. But there is a better way.

First, you run an initialization event where you link, only once, variable 213 to a script variable. And then in all your script calls you use the script variable and not the RPGM variable. This is called separation of concepts.

Your autorun initialization event that runs once on startup and links every RPGM variable against a respective script variable:

View attachment 201954

Your actual script call event:

View attachment 201955

Now, if you change your mind about using 213 and start using 1001 instead, all you need to do is change what that variable is linked to in the initialization event.

Oh, wow! Thank you for your detailed explanation!

I am new to MZ (only started since July) and new to JS, so I'll try my best to understand.

window.glb = {} I guess this is to use the "glb" method of the window object to create an empty object? Or is it to create a new property called .glb under the window object and give it an empty object?

window.glb.rgbg = [0, 0, 0, 0] To create an empty array?

window.glb.rgbg[0] = $gameVariables.value(213).
window.glb.rgbg[1] = $gameVariables.value(214).
window.glb.rgbg[2] = $gameVariables.value(215).
window.glb.rgbg[3] = $gameVariables.value(216).

So bascially the code will be:
window.glb.rgbg = [$gameVariables.value(213), $gameVariables.value(214), $gameVariables.value(215), $gameVariables.value(216)]

And then you store the duration value to:
window.glb.dur

This is the part I don't get:
hlp.print(window.glb.rgbg)

I googled it, and it turns out to be something related to three.js?

Thank you, I think my knowledge of Javascript just got better. :)
 

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
57
Reaction score
28
First Language
English
Primarily Uses
RMMZ
@dm604

Looks like you have a solid programming background, so RPGM's JS is all about figuring out patterns and best practices to minimize eventual maintenance.

Q: Or is it to create a new property called .glb under the window object and give it an empty object?
A: Yes. You basically allocate a storage pocket on the "window" object to ensure the data is always in scope and can be accessible from anywhere. You carve it out for yourself with a unique name: window.glb or window.global or window.myG.

Q: This is the part I don't get: hlp.print(window.glb.rgbg)
A: My bad, this is a leftover from me testing the code I posted. I forgot to delete the hlp.print which is one of my utility functions.

For what it is worth, as you start having more JS-inserts, do start having wrapper classes and functions around both JS and RPGM's API. I.e. your tint function could very well end up in a wrapper somewhere.

I.e. here are snippers of my wrappers, respective from: "helpers.js" and "RPGM_wrappers.js"

JavaScript:
class hlp{
    static print(message){
        console.log(message)
    }    
}

JavaScript:
class RPGM_API_Wrappers{
    static toggle_switch (rpgm_switch, state) {      
        $gameSwitches.setValue(rpgm_switch, state)
    }
}
 
Last edited:

Latest Threads

Latest Profile Posts

Finally got my website fixed and the security sorted so it's been a productive day. Can I go to sleep now? I mean... I don't need to work right?
It's always a good idea to refresh yourself on what your plugins do. I'm working on a map with opening walls, and I was about to tear my hair out over how much image editing and hand-constructing of autotiles I'd have to do, when I looked again and saw @Shaz 's Tile Changer could copy areas from another map.
"sorry it took me so long to respond" - can we please agree not to say that anymore unless it actually took a long time?! (Like 36hrs at least) I mean, I'm running out of funny responses here xD
Ugh... 4:53AM over here and I can't sleep so why not just game make.
I just love the MV feature that allows you to create your own animations!

Forum statistics

Threads
115,919
Messages
1,094,013
Members
151,174
Latest member
sardin
Top