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

dm604

Veteran
Veteran
Joined
Sep 18, 2021
Messages
46
Reaction score
15
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
46
Reaction score
15
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
46
Reaction score
15
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

A certain person better sell his stock while he still can, because it looks like it's going to take an unrecoverable nose dive.
7 years of trying to plan this project... and it got an official plotline today. 7 years. I really just have no concept of order huh GHJGSJHGVGHASFH.
Doing RPG Maker News for 24th October 2021

I'm not sure how to do this so I'll just ask here, Wheres a good place to post your game (for free) once its done?
I don't know what I'm doing :D

Forum statistics

Threads
116,063
Messages
1,095,439
Members
151,424
Latest member
Bratio
Top