There must be a better way to structure this code

Syberduh

Veteran
Veteran
Joined
Jul 26, 2021
Messages
31
Reaction score
17
First Language
English
Primarily Uses
RMMZ
Newbie coder question:

Below is code for flickering torchlight. The result is reasonably good but I'm more interested in the structure of the code. It's based on two independent variables (one for torch brightness and one for how long the torch stays at a particular brightness). It's currently handled with an ugly series of nested conditionals and I assume there's a much better way to organize it. Is there a general coding principle I can apply here?

//TorchExtremeAvoid keeps the light from bouncing directly between brightest and dimmest settings. (Creates a jarring effect when it happens).


◆Label:AAA ◆Control Variables:#0004 Torchflicker = Random 0..10 ◆Control Variables:#0005 TorchSustain = Random 0..10 ◆If:Torchflicker < 1 ◆If:TorchExtremeAvoid = 2 ◆Jump to Label:AAA ◆ :End ◆Control Variables:#0006 TorchExtremeAvoid = 1 ◆If:TorchSustain < 2 ◆Tint Screen:(-136,-136,-136,0), 2 frames (Wait) ◆Tint Screen:(-153,-153,-153,0), 2 frames (Wait) ◆ :Else ◆If:TorchSustain < 4 ◆Tint Screen:(-136,-136,-136,0), 4 frames (Wait) ◆Tint Screen:(-153,-153,-153,0), 4 frames (Wait) ◆ :Else ◆If:TorchSustain < 6 ◆Tint Screen:(-136,-136,-136,0), 6 frames (Wait) ◆Tint Screen:(-153,-153,-153,0), 6 frames (Wait) ◆ :Else ◆If:TorchSustain < 8 ◆Tint Screen:(-136,-136,-136,0), 8 frames (Wait) ◆Tint Screen:(-153,-153,-153,0), 8 frames (Wait) ◆ :Else ◆Tint Screen:(-136,-136,-136,0), 10 frames (Wait) ◆Tint Screen:(-153,-153,-153,0), 10 frames (Wait) ◆ :End ◆ :End ◆ :End ◆ :End ◆ :Else ◆If:Torchflicker < 2 ◆Control Variables:#0006 TorchExtremeAvoid = 0 ◆If:TorchSustain < 2 ◆Tint Screen:(-119,-119,-119,0), 2 frames (Wait) ◆Tint Screen:(-136,-136,-136,0), 2 frames (Wait) ◆ :Else ◆If:TorchSustain < 4 ◆Tint Screen:(-119,-119,-119,0), 4 frames (Wait) ◆Tint Screen:(-136,-136,-136,0), 4 frames (Wait) ◆ :Else ◆If:TorchSustain < 6 ◆Tint Screen:(-119,-119,-119,0), 6 frames (Wait) ◆Tint Screen:(-136,-136,-136,0), 6 frames (Wait) ◆ :Else ◆If:TorchSustain < 8 ◆Tint Screen:(-119,-119,-119,0), 8 frames (Wait) ◆Tint Screen:(-136,-136,-136,0), 8 frames (Wait) ◆ :Else ◆Tint Screen:(-119,-119,-119,0), 10 frames (Wait) ◆Tint Screen:(-136,-136,-136,0), 10 frames (Wait) ◆ :End ◆ :End ◆ :End ◆ :End ◆ :Else ◆If:Torchflicker < 3 ◆Control Variables:#0006 TorchExtremeAvoid = 0 ◆If:TorchSustain < 2 ◆Tint Screen:(-100,-104,-100,0), 2 frames (Wait) ◆Tint Screen:(-121,-117,-121,0), 2 frames (Wait) ◆ :Else ◆If:TorchSustain < 4 ◆Tint Screen:(-100,-100,-100,0), 4 frames (Wait) ◆Tint Screen:(-121,-121,-121,0), 4 frames (Wait) ◆ :Else ◆If:TorchSustain < 6 ◆Tint Screen:(-98,-102,-102,0), 6 frames (Wait) ◆Tint Screen:(-115,-119,-119,0), 6 frames (Wait) ◆ :Else ◆If:TorchSustain < 8 ◆Tint Screen:(-100,-100,-104,0), 8 frames (Wait) ◆Tint Screen:(-117,-117,-121,0), 8 frames (Wait) ◆ :Else ◆Tint Screen:(-98,-101,-104,0), 10 frames (Wait) ◆Tint Screen:(-117,-121,-117,0), 10 frames (Wait) ◆ :End ◆ :End ◆ :End ◆ :End ◆ :Else ◆If:Torchflicker < 4 ◆Control Variables:#0006 TorchExtremeAvoid = 0 ◆If:TorchSustain < 2 ◆Tint Screen:(-85,-85,-85,0), 2 frames (Wait) ◆Tint Screen:(-102,-102,-102,0), 2 frames (Wait) ◆ :Else ◆If:TorchSustain < 4 ◆Tint Screen:(-85,-85,-85,0), 4 frames (Wait) ◆Tint Screen:(-102,-102,-102,0), 4 frames (Wait) ◆ :Else ◆If:TorchSustain < 6 ◆Tint Screen:(-85,-85,-85,0), 6 frames (Wait) ◆Tint Screen:(-102,-102,-102,0), 6 frames (Wait) ◆ :Else ◆If:TorchSustain < 8 ◆Tint Screen:(-85,-85,-85,0), 8 frames (Wait) ◆Tint Screen:(-102,-102,-102,0), 8 frames (Wait) ◆ :Else ◆Tint Screen:(-85,-85,-85,0), 10 frames (Wait) ◆Tint Screen:(-102,-102,-102,0), 10 frames (Wait) ◆ :End ◆ :End ◆ :End ◆ :End ◆ :Else ◆If:Torchflicker < 5 ◆ :Else ◆If:TorchExtremeAvoid = 1 ◆Jump to Label:AAA ◆ :End ◆Control Variables:#0006 TorchExtremeAvoid = 2 ◆Tint Screen:(-102,-102,-102,0), 10 frames (Wait) ◆Tint Screen:(-105,-105,-105,0), 15 frames (Wait) ◆ :End ◆ :End ◆ :End ◆ :End ◆ :End
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,772
Reaction score
1,623
First Language
English
Primarily Uses
RMMV
Yes and no. I didn't read the event super thoroughly, but I've seen similar things - it's hard to get much more efficient in an event because you're only kind of coding. Being at the mercy of the predefined event commands, there's a limit to how much you can customize for efficiency.

If you were to take that out of an event and actually write it in the equivalent JavaScript (possibly fitting it into a Script box inside an event, or as a function in a plugin), you could make it much more efficient via additional conditional operands or assigning variables so you don't have to constantly write out the full function calls.

I am curious about one bit at the bottom - you have If TorchFlicker<5, and then it's empty, going directly to an Else where you do stuff. Why not just say if TorchFlicker >= 5, do that stuff, eliminate the need for an Else there? It doesn't really impact anything in the event, just a place where you could get rid of a few lines.
 

Syberduh

Veteran
Veteran
Joined
Jul 26, 2021
Messages
31
Reaction score
17
First Language
English
Primarily Uses
RMMZ
Thanks! Makes sense that I can't do much more without digging into actual JavaScript.

The TorchFlicker<5 is just a residual conditional that used to contain another set of tint commands that I removed (the torch would occasionally flare up brighter than the baseline but it didn't look right). I figured I would just leave that as a sort of reserved spot in case I decided to tinker with it again since it doesn't seem to be hurting anything. That's probably bad practice because if I come back to it after a few months I'll probably spend a while thinking "Why is this TorchFlicker<5 here?"
 

Etarxer

Veteran
Veteran
Joined
Sep 14, 2020
Messages
38
Reaction score
5
First Language
English
Primarily Uses
RMMZ
Thanks! Makes sense that I can't do much more without digging into actual JavaScript.

The TorchFlicker<5 is just a residual conditional that used to contain another set of tint commands that I removed (the torch would occasionally flare up brighter than the baseline but it didn't look right). I figured I would just leave that as a sort of reserved spot in case I decided to tinker with it again since it doesn't seem to be hurting anything. That's probably bad practice because if I come back to it after a few months I'll probably spend a while thinking "Why is this TorchFlicker<5 here?"

If you're going to leave a placeholder like that, I would suggest leaving a comment in its place. Explain what you were trying to do, so future you can remember.
 

Syberduh

Veteran
Veteran
Joined
Jul 26, 2021
Messages
31
Reaction score
17
First Language
English
Primarily Uses
RMMZ
Attempt number 1 at code optimization:

JavaScript:
var torchFlicker;
var torchSustain;
var torchExtremeAvoid;

torchFlicker = Math.floor(Math.random()*10) +1;
torchSustain = Math.floor(Math.random()*5) +1;

switch (torchFlicker) {
  case 1:
        if (torchExtremeAvoid === 2) {$gameScreen.startTint([-119,-119,-119,0], 6); this.wait(6); $gameScreen.startTint([-136,-136,-136,0], 6); this.wait(6);}
        torchExtremeAvoid = 1;
        switch (torchSustain) {
          case 1: $gameScreen.startTint([-136,-136,-136,0], 2); this.wait(2); $gameScreen.startTint([-153,-153,-153,0], 2); this.wait(2); break;           
          case 2: $gameScreen.startTint([-136,-136,-136,0], 4); this.wait(4); $gameScreen.startTint([-153,-153,-153,0], 4); this.wait(4); break;
          case 3: $gameScreen.startTint([-136,-136,-136,0], 6); this.wait(6); $gameScreen.startTint([-153,-153,-153,0], 6); this.wait(6); break;
          case 4: $gameScreen.startTint([-136,-136,-136,0], 8); this.wait(8); $gameScreen.startTint([-153,-153,-153,0], 8); this.wait(8); break;
          case 5: $gameScreen.startTint([-136,-136,-136,0], 10); this.wait(10); $gameScreen.startTint([-153,-153,-153,0], 10); this.wait(10);
          }           
break;

  case 2:
        torchExtremeAvoid = 0;
        switch (torchSustain) {
          case 1: $gameScreen.startTint([-119,-119,-119,0], 2); this.wait(2); $gameScreen.startTint([-136,-136,-136,0], 2); this.wait(2); break;           
          case 2: $gameScreen.startTint([-119,-119,-119,0], 4); this.wait(4); $gameScreen.startTint([-136,-136,-136,0], 4); this.wait(4); break;
          case 3: $gameScreen.startTint([-119,-119,-119,0], 6); this.wait(6); $gameScreen.startTint([-136,-136,-136,0], 6); this.wait(6); break;
          case 4: $gameScreen.startTint([-119,-119,-119,0], 8); this.wait(8); $gameScreen.startTint([-136,-136,-136,0], 8); this.wait(8); break;
          case 5: $gameScreen.startTint([-119,-119,-119,0], 10); this.wait(10); $gameScreen.startTint([-136,-136,-136,0], 10); this.wait(10);
          }           
break;
 
  case 3:     
        torchExtremeAvoid = 0;   
        switch (torchSustain) {
          case 1: $gameScreen.startTint([-100,-104,-100,0], 2); this.wait(2); $gameScreen.startTint([-121,-117,-121,0], 2); this.wait(2); break;           
          case 2: $gameScreen.startTint([-100,-104,-100,0], 4); this.wait(4); $gameScreen.startTint([-121,-117,-121,0], 4); this.wait(4); break;
          case 3: $gameScreen.startTint([-100,-104,-100,0], 6); this.wait(6); $gameScreen.startTint([-121,-117,-121,0], 6); this.wait(6); break;
          case 4: $gameScreen.startTint([-100,-104,-100,0], 8); this.wait(8); $gameScreen.startTint([-121,-117,-121,0], 8); this.wait(8); break;
          case 5: $gameScreen.startTint([-100,-104,-100,0], 10); this.wait(10); $gameScreen.startTint([-121,-117,-121,0], 10); this.wait(10);
          }
break;
 
  case 4:     
        if (torchExtremeAvoid === 1) {$gameScreen.startTint([-119,-119,-119,0], 6); this.wait(6); $gameScreen.startTint([-136,-136,-136,0], 6); this.wait(6);}
        torchExtremeAvoid = 2;
        switch (torchSustain) {
          case 1: $gameScreen.startTint([-95,-95,-95,0], 2); this.wait(2); $gameScreen.startTint([-102,-102,-102,0], 2); this.wait(2); break;         
          case 2: $gameScreen.startTint([-95,-95,-95,0], 4); this.wait(4); $gameScreen.startTint([-102,-102,-102,0], 4); this.wait(4); break;
          case 3: $gameScreen.startTint([-95,-95,-95,0], 6); this.wait(6); $gameScreen.startTint([-102,-102,-102,0], 6); this.wait(6); break;
          case 4: $gameScreen.startTint([-95,-95,-95,0], 8); this.wait(8); $gameScreen.startTint([-102,-102,-102,0], 8); this.wait(8); break;
          case 5: $gameScreen.startTint([-95,-95,-95,0], 10); this.wait(10); $gameScreen.startTint([-102,-102,-102,0], 10); this.wait(10);
          }   

break;
  default:

        if (torchExtremeAvoid === 1) {$gameScreen.startTint([-100,-104,-100,0], 6); this.wait(6); $gameScreen.startTint([-121,-117,-121,0], 6); this.wait(6);}
        torchExtremeAvoid = 2;
        $gameScreen.startTint([-102,-102,-102,0], 8); this.wait(8); $gameScreen.startTint([-105,-105,-105,0], 10); this.wait(10);
          
}

It's certainly nicer to look at than the nested conditionals. If only those wait commands actually worked in a script... oops.

So anyway, here's attempt number 2:

JavaScript:
◆Script:$gameVariables.setValue(4, Math.floor(Math.random()*11) +1);
:      :$gameVariables.setValue(5, Math.floor(Math.random()*5) +1);
:      :
:      :switch ($gameVariables.value(4)) {
:      :  case 1: 
:      :if ($gameVariables.value(6) === 2) {$gameScreen.startTint([-119,-119,-119,0], 2); $gameVariables.setValue(7, 2); }
:      :$gameVariables.setValue(6, 1);
:      :switch ($gameVariables.value(5)) {
:      :  case 1: $gameScreen.startTint([-136,-136,-136,0], 2); $gameVariables.setValue(7, 2); break;           
:      :  case 2: $gameScreen.startTint([-136,-136,-136,0], 4); $gameVariables.setValue(7, 4); break;
:      :  case 3: $gameScreen.startTint([-136,-136,-136,0], 6); $gameVariables.setValue(7, 6); break;
:      :  case 4: $gameScreen.startTint([-136,-136,-136,0], 8); $gameVariables.setValue(7, 8); break;
:      :  case 5: $gameScreen.startTint([-136,-136,-136,0], 10); $gameVariables.setValue(7, 10); 
:      :  }           
:      :break;
:      :
:      :  case 2: 
:      :$gameVariables.setValue(6, 0);
:      :switch ($gameVariables.value(5)) {
:      :  case 1: $gameScreen.startTint([-119,-119,-119,0], 2); $gameVariables.setValue(7, 2); break;           
:      :  case 2: $gameScreen.startTint([-119,-119,-119,0], 4); $gameVariables.setValue(7, 4); break;
:      :  case 3: $gameScreen.startTint([-119,-119,-119,0], 6); $gameVariables.setValue(7, 6); break;
:      :  case 4: $gameScreen.startTint([-119,-119,-119,0], 8); $gameVariables.setValue(7, 8); break;
:      :  case 5: $gameScreen.startTint([-119,-119,-119,0], 10); $gameVariables.setValue(7, 10); 
:      :  }            
:      :break;
:      :  
:      :  case 3: 
:      :$gameVariables.setValue(6, 0);
:      :switch ($gameVariables.value(5)) {
:      :  case 1: $gameScreen.startTint([-100,-104,-100,0], 2); $gameVariables.setValue(7, 2); break;           
:      :  case 2: $gameScreen.startTint([-100,-104,-100,0], 4); $gameVariables.setValue(7, 4); break;
:      :  case 3: $gameScreen.startTint([-100,-104,-100,0], 6); $gameVariables.setValue(7, 6); break;
:      :  case 4: $gameScreen.startTint([-100,-104,-100,0], 8); $gameVariables.setValue(7, 8); break;
:      :  case 5: $gameScreen.startTint([-100,-104,-100,0], 10); $gameVariables.setValue(7, 10);
:      :  }
:      :break;
:      :  
:      :  case 4: 
:      :if ($gameVariables.value(6) === 1) {$gameScreen.startTint([-119,-119,-119,0], 4); $gameVariables.setValue(7, 4);}
:      :$gameVariables.setValue(6, 2);
:      :switch ($gameVariables.value(5)) {
:      :  case 1: $gameScreen.startTint([-95,-95,-95,0], 2); $gameVariables.setValue(7, 2); break;          
:      :  case 2: $gameScreen.startTint([-95,-95,-95,0], 4); $gameVariables.setValue(7, 4); break;
:      :  case 3: $gameScreen.startTint([-95,-95,-95,0], 6); $gameVariables.setValue(7, 6); break;
:      :  case 4: $gameScreen.startTint([-95,-95,-95,0], 8); $gameVariables.setValue(7, 8); break;
:      :  case 5: $gameScreen.startTint([-95,-95,-95,0], 10); $gameVariables.setValue(7, 10);  
:      :  }
:      :
:      :break;
:      :  default: 
:      :
:      :if ($gameVariables.value(6) === 1) {$gameScreen.startTint([-100,-104,-100,0], 2); $gameVariables.setValue(7, 2); }
:      :$gameVariables.setValue(6, 2);
:      :$gameScreen.startTint([-102,-102,-102,0], 10); $gameVariables.setValue(7, 10);
:      :  
:      :}
◆Script:this.wait($gameVariables.value(7));
◆Script:switch ($gameVariables.value(4)) {
:      :  case 1: 
:      :if ($gameVariables.value(6) === 2) {$gameScreen.startTint([-136,-136,-136,0], 2); $gameVariables.setValue(7, 2);}
:      :$gameVariables.setValue(6, 1);
:      :switch ($gameVariables.value(5)) {
:      :  case 1: $gameScreen.startTint([-153,-153,-153,0], 2); $gameVariables.setValue(7, 2); break;           
:      :  case 2: $gameScreen.startTint([-153,-153,-153,0], 4); $gameVariables.setValue(7, 4); break;
:      :  case 3: $gameScreen.startTint([-153,-153,-153,0], 6); $gameVariables.setValue(7, 6); break;
:      :  case 4: $gameScreen.startTint([-153,-153,-153,0], 8); $gameVariables.setValue(7, 8); break;
:      :  case 5: $gameScreen.startTint([-153,-153,-153,0], 10); $gameVariables.setValue(7, 10);
:      :  }           
:      :break;
:      :
:      :  case 2: 
:      :$gameVariables.setValue(6, 0);
:      :switch ($gameVariables.value(5)) {
:      :  case 1: $gameScreen.startTint([-136,-136,-136,0], 2); $gameVariables.setValue(7, 2); break;           
:      :  case 2: $gameScreen.startTint([-136,-136,-136,0], 4); $gameVariables.setValue(7, 4); break;
:      :  case 3: $gameScreen.startTint([-136,-136,-136,0], 6); $gameVariables.setValue(7, 6); break;
:      :  case 4: $gameScreen.startTint([-136,-136,-136,0], 8); $gameVariables.setValue(7, 8); break;
:      :  case 5: $gameScreen.startTint([-136,-136,-136,0], 10); $gameVariables.setValue(7, 10);
:      :  }            
:      :break;
:      :  
:      :  case 3: 
:      :$gameVariables.setValue(6, 0);
:      :switch ($gameVariables.value(5)) {
:      :  case 1: $gameScreen.startTint([-121,-117,-121,0], 2); $gameVariables.setValue(7, 2); break;           
:      :  case 2: $gameScreen.startTint([-121,-117,-121,0], 4); $gameVariables.setValue(7, 4); break;
:      :  case 3: $gameScreen.startTint([-121,-117,-121,0], 6); $gameVariables.setValue(7, 6); break;
:      :  case 4: $gameScreen.startTint([-121,-117,-121,0], 8); $gameVariables.setValue(7, 8); break;
:      :  case 5: $gameScreen.startTint([-121,-117,-121,0], 10); $gameVariables.setValue(7, 10);
:      :  }
:      :break;
:      :  
:      :  case 4: 
:      :if ($gameVariables.value(6) === 1) {$gameScreen.startTint([-136,-136,-136,0], 4); $gameVariables.setValue(7, 4);}
:      :$gameVariables.setValue(6, 2);
:      :switch ($gameVariables.value(5)) {
:      :  case 1: $gameScreen.startTint([-102,-102,-102,0], 2); $gameVariables.setValue(7, 2); break;          
:      :  case 2: $gameScreen.startTint([-102,-102,-102,0], 4); $gameVariables.setValue(7, 4); break;
:      :  case 3: $gameScreen.startTint([-102,-102,-102,0], 6); $gameVariables.setValue(7, 6); break;
:      :  case 4: $gameScreen.startTint([-102,-102,-102,0], 8); $gameVariables.setValue(7, 8); break;
:      :  case 5: $gameScreen.startTint([-102,-102,-102,0], 10); $gameVariables.setValue(7, 10);
:      :  }
:      :
:      :break;
:      :  default: 
:      :
:      :if ($gameVariables.value(6) === 1) {$gameScreen.startTint([-121,-117,-121,0], 2); $gameVariables.setValue(7, 2);}
:      :$gameVariables.setValue(6, 2);
:      :$gameScreen.startTint([-105,-105,-105,0], 15); $gameVariables.setValue(7, 15);
:      :}
◆Script:this.wait($gameVariables.value(7));

So I had to split this into 3 separate scripts,

1: Tell the torch how to get brighter and assign a value to the variable that tells it how long to shine,
2: Call the value of that variable in a separate this.wait script
3: Tell the torch how to get dimmer and assign a variable that tells it how long to stay dim
4: Call the value of that variable in a separate this.wait script
5: repeat

To get the separate scripts to talk to each other I had to use $globalvariables. I thought I could declare a global variable with var but it didn't seem to be working.

I also tried stuff like
var torchFlicker = $gameVariables.value(5);

just so I could reference it within a given script using a more familiar variable name but I was getting an undefined error when I called torchFlicker so I just replaced everything with the $globalvariable references. Was I just messing up the syntax or is that a logic issue?
 

Syberduh

Veteran
Veteran
Joined
Jul 26, 2021
Messages
31
Reaction score
17
First Language
English
Primarily Uses
RMMZ
Finally a true optimization. I realized there was no need to hard code the duration of the changes in brightness. I'm already generating a variable in the range that I want so I can just plug that variable in as the duration during each iteration of the flicker.

General principle that noobs like me may find useful: if you have something that's iterating in a very predictable way over and over like in the examples above, there's a better way to do it.

This thread probably now belongs in learning javascript
JavaScript:
$gameVariables.setValue(4, Math.floor(Math.random()*10) +1);
$gameVariables.setValue(5, Math.floor(Math.random()*5) +1);
let x = $gameVariables.value(5);

switch ($gameVariables.value(4)) {
  case 1:
    if ($gameVariables.value(6) === 2) {$gameScreen.startTint([-119,-119,-119,0], 2); $gameVariables.setValue(7, 2); }
    $gameVariables.setValue(6, 1);
    $gameScreen.startTint([-136,-136,-136,0], x*2); $gameVariables.setValue(7, x*2);       
break;
  case 2:
    $gameVariables.setValue(6, 0);
    $gameScreen.startTint([-119,-119,-119,0], x*2); $gameVariables.setValue(7, x*2);
break;
  case 3:  
    $gameVariables.setValue(6, 0);
    $gameScreen.startTint([-100,-104,-100,0], x*2); $gameVariables.setValue(7, x*2);        
break;
  case 4:  
    if ($gameVariables.value(6) === 1) {$gameScreen.startTint([-119,-119,-119,0], 4); $gameVariables.setValue(7, 4);}
    $gameVariables.setValue(6, 2);
    $gameScreen.startTint([-95,-95,-95,0], x*2); $gameVariables.setValue(7, x*2);       
break;
  default: //torchFlicker is baseline
    if ($gameVariables.value(6) === 1) {$gameScreen.startTint([-100,-104,-100,0], 2); $gameVariables.setValue(7, 2); }
    $gameVariables.setValue(6, 2);
    $gameScreen.startTint([-102,-102,-102,0], 10); $gameVariables.setValue(7, 10);
}
//Separate Script
this.wait($gameVariables.value(7) / 1.5);
//Separate Script
let x = $gameVariables.value(5);

switch ($gameVariables.value(4)) {
  case 1:
    if ($gameVariables.value(6) === 2) {$gameScreen.startTint([-136,-136,-136,0], 2); $gameVariables.setValue(7, 2);}
    $gameVariables.setValue(6, 1);
    $gameScreen.startTint([-153,-153,-153,0], x*2); $gameVariables.setValue(7, x*2);
break;
  case 2:
    $gameVariables.setValue(6, 0);
    $gameScreen.startTint([-136,-136,-136,0], x*2); $gameVariables.setValue(7, x*2);
break;
  case 3:  
    $gameVariables.setValue(6, 0); 
    $gameScreen.startTint([-121,-117,-121,0], x*2); $gameVariables.setValue(7, x*2);
break;
  case 4:  
    if ($gameVariables.value(6) === 1) {$gameScreen.startTint([-136,-136,-136,0], 4); $gameVariables.setValue(7, 4);}
    $gameVariables.setValue(6, 2);
    $gameScreen.startTint([-102,-102,-102,0], x*2); $gameVariables.setValue(7, x*2);       
break;
  default: //torchFlicker is baseline

    if ($gameVariables.value(6) === 1) {$gameScreen.startTint([-121,-117,-121,0], 2); $gameVariables.setValue(7, 2);}
    $gameVariables.setValue(6, 2);
    $gameScreen.startTint([-105,-105,-105,0], 15); $gameVariables.setValue(7, 15);
}

}

Edit: stray strings commented out to avoid any potential issues
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,772
Reaction score
1,623
First Language
English
Primarily Uses
RMMV
What's with that string after your default statement? That doesn't throw any warnings in your game?
 

Syberduh

Veteran
Veteran
Joined
Jul 26, 2021
Messages
31
Reaction score
17
First Language
English
Primarily Uses
RMMZ
Strangely enough it does not cause any warnings or error messages. But yes it's just a note to myself and should be commented out.
 

Syberduh

Veteran
Veteran
Joined
Jul 26, 2021
Messages
31
Reaction score
17
First Language
English
Primarily Uses
RMMZ
Welp turns out this is all you really need for a pretty decent flickering effect. The multiplication factors on x and the this.wait scripts can be tweaked provide a more dramatic or more relaxed flicker.

JavaScript:
$gameVariables.setValue(4, Math.floor(Math.random()*10) +1);
$gameVariables.setValue(5, Math.floor(Math.random()*5) +1);
let x = $gameVariables.value(5);
let y = $gameVariables.value(4);
 
$gameScreen.startTint([-95-(40/y),-95-(40/y),-95-(40/y),0], x*4); 
$gameVariables.setValue(7, x*2);

//Separate Script
this.wait($gameVariables.value(7) / 0.5);
//Separate Script

let x = $gameVariables.value(5);
let y = $gameVariables.value(4);

$gameScreen.startTint([-102-(50/y),-102-(50/y),-102-(50/y),0], x*4); 
$gameVariables.setValue(7, x*2);

//Separate Script
this.wait($gameVariables.value(7) / 0.5);
 

Latest Threads

Latest Posts

Latest Profile Posts

Making games is the only thing I'm good at. Real talk.
So, uh... where's the RPG Maker MZ update with the MV animation system? Is there a release date confirmed?
Also I'm kind of brave enough to admit this. I... I have a crush on Sephiroth.
Please don't call me anything offensive. I'm naturally crazy.
thanks to a lot of lunatic coding... my game finally has a stun mechanic that I feel really good about. damage enemy's mental psyche (mp), and once empty, hitting with certain attacks trigger combos that can stack the damage.
Waiting for the 1.40 update before testing out my copy of MZ so that I don't end up adding unnecessary work to my plate. Meanwhile the current fourth draft for my story is taking shape, and I'm fleshing out the lore as I realize how things would make better sense here and there for the world that I'm building.
Sword_of_Dusk wrote on BCj's profile.
Just found out about your complications. I'm so sorry that you're going through this. I wish I could do something substantial for you, but our distance from each other makes that an impossibility. Still, if you ever need to talk or vent, I'm here.

Forum statistics

Threads
117,112
Messages
1,104,680
Members
153,149
Latest member
gabbothedead
Top