Script & Line Counter
Authors: gameus
Version: 1.1
Type: Line Counting Utility
Key Term: Scripting Tool
IntroductionEver wonder how many lines of code are in your game? Or just in a particular script? Look no further! This script counds all the lines of code, comments and empty lines for every script in your project. It writes everything to a file. Also counts the number of scripts in your project.
Features
- Counts code, empty lines, and comments and total scripts
- Can omit scripts
- Can count only certain scripts
- Writes everything to a file
- Now detects quote blocks (=begin =end)
ScreenshotsThe result of a default project scan (with this script added).
Game_Temp
-Lines of Code: 94
-Comments: 12
-Empty Lines: 1
-Total: 107
Game_System
-Lines of Code: 124
-Comments: 86
-Empty Lines: 1
-Total: 211
Game_Switches
-Lines of Code: 17
-Comments: 18
-Empty Lines: 1
-Total: 36
Game_Variables
-Lines of Code: 17
-Comments: 18
-Empty Lines: 1
-Total: 36
Game_SelfSwitches
-Lines of Code: 11
-Comments: 18
-Empty Lines: 1
-Total: 30
Game_Screen
-Lines of Code: 110
-Comments: 37
-Empty Lines: 1
-Total: 148
Game_Picture
-Lines of Code: 105
-Comments: 50
-Empty Lines: 1
-Total: 156
Game_Battler 1
-Lines of Code: 198
-Comments: 108
-Empty Lines: 1
-Total: 307
Game_Battler 2
-Lines of Code: 178
-Comments: 115
-Empty Lines: 1
-Total: 294
Game_Battler 3
-Lines of Code: 224
-Comments: 129
-Empty Lines: 1
-Total: 354
Game_BattleAction
-Lines of Code: 94
-Comments: 50
-Empty Lines: 1
-Total: 145
Game_Actor
-Lines of Code: 410
-Comments: 184
-Empty Lines: 1
-Total: 595
Game_Enemy
-Lines of Code: 179
-Comments: 137
-Empty Lines: 1
-Total: 317
Game_Actors
-Lines of Code: 14
-Comments: 13
-Empty Lines: 1
-Total: 28
Game_Party
-Lines of Code: 197
-Comments: 159
-Empty Lines: 1
-Total: 357
Game_Troop
-Lines of Code: 44
-Comments: 39
-Empty Lines: 1
-Total: 84
Game_Map
-Lines of Code: 262
-Comments: 156
-Empty Lines: 1
-Total: 419
Game_CommonEvent
-Lines of Code: 36
-Comments: 33
-Empty Lines: 1
-Total: 70
Game_Character 1
-Lines of Code: 182
-Comments: 119
-Empty Lines: 1
-Total: 302
Game_Character 2
-Lines of Code: 255
-Comments: 95
-Empty Lines: 1
-Total: 351
Game_Character 3
-Lines of Code: 302
-Comments: 181
-Empty Lines: 1
-Total: 484
Game_Event
-Lines of Code: 146
-Comments: 79
-Empty Lines: 1
-Total: 226
Game_Player
-Lines of Code: 166
-Comments: 111
-Empty Lines: 1
-Total: 278
Sprite_Character
-Lines of Code: 49
-Comments: 27
-Empty Lines: 1
-Total: 77
Sprite_Battler
-Lines of Code: 93
-Comments: 37
-Empty Lines: 1
-Total: 131
Sprite_Picture
-Lines of Code: 43
-Comments: 28
-Empty Lines: 1
-Total: 72
Sprite_Timer
-Lines of Code: 31
-Comments: 21
-Empty Lines: 1
-Total: 53
Spriteset_Map
-Lines of Code: 111
-Comments: 44
-Empty Lines: 1
-Total: 156
Spriteset_Battle
-Lines of Code: 85
-Comments: 46
-Empty Lines: 1
-Total: 132
Window_Base
-Lines of Code: 198
-Comments: 122
-Empty Lines: 1
-Total: 321
Window_Selectable
-Lines of Code: 110
-Comments: 92
-Empty Lines: 1
-Total: 203
Window_Command
-Lines of Code: 25
-Comments: 23
-Empty Lines: 1
-Total: 49
Window_Help
-Lines of Code: 37
-Comments: 23
-Empty Lines: 1
-Total: 61
Window_Gold
-Lines of Code: 15
-Comments: 11
-Empty Lines: 1
-Total: 27
Window_PlayTime
-Lines of Code: 25
-Comments: 14
-Empty Lines: 1
-Total: 40
Window_Steps
-Lines of Code: 14
-Comments: 11
-Empty Lines: 1
-Total: 26
Window_MenuStatus
-Lines of Code: 33
-Comments: 14
-Empty Lines: 1
-Total: 48
Window_Item
-Lines of Code: 77
-Comments: 26
-Empty Lines: 1
-Total: 104
Window_Skill
-Lines of Code: 57
-Comments: 25
-Empty Lines: 1
-Total: 83
Window_SkillStatus
-Lines of Code: 15
-Comments: 12
-Empty Lines: 1
-Total: 28
Window_Target
-Lines of Code: 32
-Comments: 16
-Empty Lines: 1
-Total: 49
Window_EquipLeft
-Lines of Code: 42
-Comments: 18
-Empty Lines: 1
-Total: 61
Window_EquipRight
-Lines of Code: 36
-Comments: 19
-Empty Lines: 1
-Total: 56
Window_EquipItem
-Lines of Code: 65
-Comments: 28
-Empty Lines: 1
-Total: 94
Window_Status
-Lines of Code: 51
-Comments: 12
-Empty Lines: 1
-Total: 64
Window_SaveFile
-Lines of Code: 62
-Comments: 28
-Empty Lines: 1
-Total: 91
Window_ShopCommand
-Lines of Code: 21
-Comments: 15
-Empty Lines: 1
-Total: 37
Window_ShopBuy
-Lines of Code: 66
-Comments: 26
-Empty Lines: 1
-Total: 93
Window_ShopSell
-Lines of Code: 69
-Comments: 24
-Empty Lines: 1
-Total: 94
Window_ShopNumber
-Lines of Code: 60
-Comments: 26
-Empty Lines: 1
-Total: 87
Window_ShopStatus
-Lines of Code: 79
-Comments: 27
-Empty Lines: 1
-Total: 107
Window_NameEdit
-Lines of Code: 67
-Comments: 36
-Empty Lines: 1
-Total: 104
Window_NameInput
-Lines of Code: 120
-Comments: 42
-Empty Lines: 1
-Total: 163
Window_InputNumber
-Lines of Code: 60
-Comments: 33
-Empty Lines: 1
-Total: 94
Window_Message
-Lines of Code: 218
-Comments: 63
-Empty Lines: 1
-Total: 282
Window_PartyCommand
-Lines of Code: 24
-Comments: 17
-Empty Lines: 1
-Total: 42
Window_BattleStatus
-Lines of Code: 39
-Comments: 22
-Empty Lines: 1
-Total: 62
Window_BattleResult
-Lines of Code: 36
-Comments: 14
-Empty Lines: 1
-Total: 51
Window_DebugLeft
-Lines of Code: 39
-Comments: 17
-Empty Lines: 1
-Total: 57
Window_DebugRight
-Lines of Code: 46
-Comments: 22
-Empty Lines: 1
-Total: 69
Arrow_Base
-Lines of Code: 36
-Comments: 28
-Empty Lines: 1
-Total: 65
Arrow_Enemy
-Lines of Code: 36
-Comments: 20
-Empty Lines: 1
-Total: 57
Arrow_Actor
-Lines of Code: 25
-Comments: 19
-Empty Lines: 1
-Total: 45
Interpreter 1
-Lines of Code: 184
-Comments: 127
-Empty Lines: 1
-Total: 312
Interpreter 2
-Lines of Code: 243
-Comments: 42
-Empty Lines: 1
-Total: 286
Interpreter 3
-Lines of Code: 262
-Comments: 150
-Empty Lines: 1
-Total: 413
Interpreter 4
-Lines of Code: 226
-Comments: 100
-Empty Lines: 1
-Total: 327
Interpreter 5
-Lines of Code: 241
-Comments: 202
-Empty Lines: 1
-Total: 444
Interpreter 6
-Lines of Code: 172
-Comments: 136
-Empty Lines: 1
-Total: 309
Interpreter 7
-Lines of Code: 157
-Comments: 123
-Empty Lines: 1
-Total: 281
Scene_Title
-Lines of Code: 143
-Comments: 73
-Empty Lines: 1
-Total: 217
Scene_Map
-Lines of Code: 168
-Comments: 116
-Empty Lines: 1
-Total: 285
Scene_Menu
-Lines of Code: 137
-Comments: 75
-Empty Lines: 1
-Total: 213
Scene_Item
-Lines of Code: 127
-Comments: 77
-Empty Lines: 1
-Total: 205
Scene_Skill
-Lines of Code: 146
-Comments: 85
-Empty Lines: 1
-Total: 232
Scene_Equip
-Lines of Code: 145
-Comments: 76
-Empty Lines: 1
-Total: 222
Scene_Status
-Lines of Code: 41
-Comments: 36
-Empty Lines: 1
-Total: 78
Scene_File
-Lines of Code: 65
-Comments: 45
-Empty Lines: 1
-Total: 111
Scene_Save
-Lines of Code: 47
-Comments: 36
-Empty Lines: 1
-Total: 84
Scene_Load
-Lines of Code: 56
-Comments: 36
-Empty Lines: 1
-Total: 93
Scene_End
-Lines of Code: 62
-Comments: 45
-Empty Lines: 1
-Total: 108
Scene_Battle 1
-Lines of Code: 222
-Comments: 100
-Empty Lines: 1
-Total: 323
Scene_Battle 2
-Lines of Code: 140
-Comments: 80
-Empty Lines: 1
-Total: 221
Scene_Battle 3
-Lines of Code: 237
-Comments: 189
-Empty Lines: 1
-Total: 427
Scene_Battle 4
-Lines of Code: 308
-Comments: 143
-Empty Lines: 1
-Total: 452
Scene_Shop
-Lines of Code: 230
-Comments: 99
-Empty Lines: 1
-Total: 330
Scene_Name
-Lines of Code: 59
-Comments: 42
-Empty Lines: 1
-Total: 102
Scene_Gameover
-Lines of Code: 31
-Comments: 27
-Empty Lines: 1
-Total: 59
Scene_Debug
-Lines of Code: 124
-Comments: 65
-Empty Lines: 1
-Total: 190
Script Counter
-Lines of Code: 58
-Comments: 75
-Empty Lines: 6
-Total: 139
Main
-Lines of Code: 11
-Comments: 11
-Empty Lines: 1
-Total: 23
Total Scripts: 91
Scripts Counted: 91
Total Lines of Code: 9754
Total Comments: 5506
Total Empty Lines: 96
Total Lines: 15356
DemoN/A
Script
#===============================================================================
# Script & Line Counter
# Version 1.1
# Author gameus
#-------------------------------------------------------------------------------
# Intro:
# Ever wonder how many lines of code are in your game? Or just in a particular
# script? Look no further! This script counds all the lines of code, comments
# and empty lines for every script in your project. It writes everything to a
# file.
#
# Features:
# Counts code, empty lines, and comments and total scripts
# Can omit scripts
# Can count only certain scripts
# Writes everything to a file
# Now recognizes =begin =end quote blocks
#
# Instructions:
# There are a couple of options.
#
# When enabled, this option will close the game after counting is done.
# EXIT_ON_DONE = true/false
# When enabled, only scripts marked with {COUNT} will be counted.
# COUNT_SELECT = true/false
#
# There might be some scripts you want to omit (not count), like this one, or
# Main. All you have to do is put {OMIT} in the title. That's it!
#
# Notes:
# -Lines that look like this
# attr_reader: @variable: # insert comment here
# Will be treated as a line of code since the comment is not in front.
# -All scripts that aren't counted will be marked in the file as "Skipped"
# -This script counts every comment, line, and empty line for every script
# -All omitted scripts will still be counted towards total scripts, however,
# it will not contribute to Total Lines, Comments, or Empty Lines
# -Empty lines in comment blocks wrapped in =begin and =end will still be
# counted as empty lines.
#
# Final note. This is a useless utility, it doesn't do anything functional for
# your game, only counts code.
#
# Compatibility:
# Will literally work with everything. It could technically wrok
# when placed after Main, but then it'll only count your code if your game
# was exited properly.
#
# It's recommended to place this script at the top and put {OMIT} in it's name.
#
# Credits:
# gameus ~ For making it.
# LiTTleDRAgo ~ Inspiring me when he asked how to count lines in a script
#===============================================================================
# Options
EXIT_ON_DONE = true
COUNT_SELECT = false
# End Options
class String
#---------------------------------------------------------
# -Removes spaces and tab characters from the beginning
# of a line
#---------------------------------------------------------
def remove_open
# create copy of self
string = self
# check for tab and space
while string[0] == 32 || string[0] == 13
# remove it
string = string[1..string.size - 1]
end
# return modified string
return string
end
end
# Set variables
total_lines = 0
total_scripts = 0
scripts_count = 0
total_comments = 0
total_empty = 0
file = File.open("script count.txt", "w")
# Loop through all scripts
$RGSS_SCRIPTS.each { |array|
# Remove {OMIT} & {COUNT} from script name
name = array[1].gsub(/{OMIT}/, "").gsub(/{COUNT}/, "")
# Increment total scripts
total_scripts += 1
# Check for COUNT_SELECT and {COUNT}
if COUNT_SELECT && !array[1].include?("{COUNT}")
file.write("#{name} - Skipped\n\n") if file != nil
next
# Check for {OMIT}
elsif array[1].include?("{OMIT}")
file.write("#{name} - Skipped\n\n") if file != nil
next
end
# Split script into an array of lines
lines = array[3].split("\n").to_a
# Reset current script's variables
comments = empty = line_count = 0
# Reset comment flag
comment_block = false
# Increment scripts counted
scripts_count += 1
# Loop through lines
lines.each { |line|
line = line.remove_open
# Check for =begin, =end comment blocks
if line[0] != nil && line[0].chr == '=' && line.include?("=begin")
comment_block = true
end
if line == "" # Check for empty
empty += 1
total_empty += 1
# Check for comment
elsif line[0] != nil && line[0].chr == '#'
comments += 1
total_comments += 1
# Check for line of code
elsif line != "" && line[0].chr != '#'
if comment_block
comments += 1
total_comments += 1
else
line_count += 1
total_lines += 1
end
end
if line[0] != nil && line[0].chr == '=' && line.include?("=end")
comment_block = false
end
}
# Write current script's info
file.write("#{name}\n" +
"-Lines of Code: #{line_count}\n" +
"-Comments: #{comments}\n" +
"-Empty Lines: #{empty}\n" +
"-Total: #{line_count + empty + comments}\n\n")
}
# Write all the total info
file.write(
"Total Scripts: #{total_scripts}\n" +
"Scripts Counted: #{scripts_count}\n" +
"Total Lines of Code: #{total_lines}\n" +
"Total Comments: #{total_comments}\n" +
"Total Empty Lines: #{total_empty}\n" +
"Total Lines: #{total_empty + total_lines + total_comments}")
# Close the file
file.close
# Exit if EXIT_ON_DONE
exit if EXIT_ON_DONE
InstructionsWhile this can be placed anywhere, it's recommended to be placed at the very top. It's also recommended that you put "{OMIT}" in the name of the script to not count it's code. Explanation of script and options (including omitting scripts and counting only select scripts) are all in the script itself.
CompatibilityWill literally work with anything.
Credits and Thanks
- gameus ~ For making it.
- LiTTleDRAgo ~ Inspiring me when he asked how to count lines in a script
Author's NotesLines that look like this
attr_reader: @variable # insert comment here
Will be treated as a line of code since the comment is not in front.
All scripts that aren't counted will be marked in the file as "Skipped"
This script counts every comment, line, and empty line for every script
All omitted scripts will still be counted towards total scripts, however, it will not contribute to Total Lines, Comments, or Empty Lines
Empty lines that are in quote blocks (=begin =end) will still be counted as empty lines
Final note. This is a useless utility, it doesn't do anything functional for your game, only counts code.