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

dm604

Veteran
Veteran
Joined
Sep 18, 2021
Messages
42
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
42
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
42
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

you know, some days you get resentful that game dev is even considered a "fun job" and other days it's like, welp, time to roll up my sleeves and code these molotov cocktails
If you suck at playing trumpets, that is probably why.
Been sick with a stomach virus for seven days now. Not going to work tomorrow because I'm still contagious according to my doctor.
Much as I love my job, I really hate playing "office politics". It would be nice if I didn't have to pretend to be someone else all day long.
I wanna get back into showing off Battlers and other assets I create again. But i'm always haunted by the "It's not good/realistic enough" voices that keep me from doing so.

Maybe I should get back to it, I did enjoy showing off whatever I came up with!

Forum statistics

Threads
115,958
Messages
1,094,378
Members
151,220
Latest member
Dolton
Top