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

dm604

Veteran
Veteran
Joined
Sep 18, 2021
Messages
51
Reaction score
17
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
59
Reaction score
29
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
51
Reaction score
17
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
59
Reaction score
29
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
51
Reaction score
17
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
59
Reaction score
29
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 Posts

Latest Profile Posts

Tell it to me straight, doc. If I've been trying to piece together a "shorter" game to learn stuff outside of game jams... am I just running away from my WIP? :v
Well, I've got a party tomorrow, and my friends are coming over. I wanted to work a bit on the Fandom Scouts assets so I can be ready when that update arrives... in other news, Pizza Time Horror is getting a second teaser, and it shows Cabaret Helen's last performance before the location closed.
Also who used to be scared of Chuck E as a kid? I was! Now I love him!
The new cards and what they do:

(I am clearly not a youtuber... Haha)
Just for the record you CAN use the "Exclude unused files" successfully to trim a project down seriously even if you're doing calls to various assets via plugins and such. BUT you need to do a full playtest of pretty much every option to ensure you did get every one of those other assets added in. Then I dumped the assets into a fresh copy of the project and yay it was like 400 Meg......

Forum statistics

Threads
117,271
Messages
1,106,013
Members
153,447
Latest member
ivysabs
Top