- Joined
- Jul 26, 2021
- Messages
- 31
- Reaction score
- 19
- 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).
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