08-30-2007, 01:00 PM
TDS Languaje
by Sephirothtds
Aug 30 2007
Well even though this is technically a script it has almost no use whatsover in a game or game use.
This is more of my way of trying to learn hashes and dealing with text files, and I'm posting it more to get an opinion from more experience scripters that may understand hashes better and could have ways to improve the code itself.
As for what the script does:
It basically translates words to another set of coded words and also translates those words back into normal words.
If that was too confusing this is a simple example:
Normal: Hello I am TDS, nice to meet you.
Coded: Niccy U el DTM, rusi dy liid ayo.
I hope that clears up what it does.
Now here's the code itself and also a Demo for those of you that dont really want to do all that hard work of copying and pasting.
For this you will need to make a .txt file inside the game folder with the name "TDS Languaje Read" Without the "", and inside that file you have to put the words you wish to translate into the coded version. After that go to the other file "TDS Languaje Write" without the "" that is automatically created and open it to see the coded version of your text.
Well thanks for reading and for any feedback on it.
by Sephirothtds
Aug 30 2007
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
No support is given. If you are the owner of the thread, please contact administration.
Well even though this is technically a script it has almost no use whatsover in a game or game use.
This is more of my way of trying to learn hashes and dealing with text files, and I'm posting it more to get an opinion from more experience scripters that may understand hashes better and could have ways to improve the code itself.
As for what the script does:
It basically translates words to another set of coded words and also translates those words back into normal words.
If that was too confusing this is a simple example:
Normal: Hello I am TDS, nice to meet you.
Coded: Niccy U el DTM, rusi dy liid ayo.
I hope that clears up what it does.
Now here's the code itself and also a Demo for those of you that dont really want to do all that hard work of copying and pasting.
Script
Code:
#==============================================================================
# TDS Languaje Thingy
# Version: 1.0
# Special thanks to Stefan Gagne for the letter codes.
# And Thanks to Slipknot, xXDarkDragonXx, Silentwalker for testing it.
#==============================================================================
#------------------------------------------------------------------------------
# Well what this script does is really simple just go into the file
# TDS Languaje Read.txt and type in there what you want to read or code into
# the languaje.
#
# Remember that this was pretty much my test for hashes and dealing with info
# inside of files so as far as editing goes you're pretty much on your own.
# Enjoy.
#
# But just a simple example:
# @tds["a"] = "e"
#
# That makes the letter "a" in lowercase be the letter "e" in lowerccase.
#==============================================================================
#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
# This window deals with general command choices.
#==============================================================================
class Window_Command < Window_Selectable
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# color : text color
#--------------------------------------------------------------------------
def draw_item(index, color)
self.contents.font.color = color
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index],1)
end
end
#==============================================================================
# ** Scene_TDS_Languaje
#------------------------------------------------------------------------------
# This scene deals with traducing the coded languaje.
#==============================================================================
class Scene_TDS_Languaje
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Load database
$data_system = load_data("Data/System.rxdata")
# Make system object
$game_system = Game_System.new
# File from whic to read the coded lines
@text = IO.readlines("tds Languaje Read.txt")
# Variable to set and chomp the \n from the text
@tds_languaje_read = @text.to_s.chomp
# Hash containing all the letters and their coded traduction
@tds = {}
# Space
@tds[" "] = " ";
# Lower case letters
@tds["a"] = "e"; @tds["b"] = "p"; @tds["c"] = "s"; @tds["d"] = "t";
@tds["e"] = "i"; @tds["f"] = "w"; @tds["g"] = "k"; @tds["h"] = "n";
@tds["i"] = "u"; @tds["j"] = "v"; @tds["k"] = "g"; @tds["l"] = "c";
@tds["m"] = "l"; @tds["n"] = "r"; @tds["o"] = "y"; @tds["p"] = "b";
@tds["q"] = "x"; @tds["r"] = "h"; @tds["s"] = "m"; @tds["t"] = "d";
@tds["u"] = "o"; @tds["v"] = "f"; @tds["w"] = "z"; @tds["x"] = "q";
@tds["y"] = "a"; @tds["z"] = "j";
# Capital Letters
@tds["A"] = "E"; @tds["B"] = "P"; @tds["C"] = "S"; @tds["D"] = "T";
@tds["E"] = "I"; @tds["F"] = "W"; @tds["G"] = "K"; @tds["H"] = "N";
@tds["I"] = "U"; @tds["J"] = "V"; @tds["K"] = "G"; @tds["L"] = "C";
@tds["M"] = "L"; @tds["N"] = "R"; @tds["O"] = "Y"; @tds["P"] = "B";
@tds["Q"] = "X"; @tds["R"] = "H"; @tds["S"] = "M"; @tds["T"] = "D";
@tds["U"] = "O"; @tds["V"] = "F"; @tds["W"] = "Z"; @tds["X"] = "Q";
@tds["Y"] = "A"; @tds["Z"] = "J";
# Numbers
@tds["1"] = "1"; @tds["2"] = "2"; @tds["3"] = "3"; @tds["4"] = "4";
@tds["5"] = "5"; @tds["6"] = "6"; @tds["7"] = "7"; @tds["8"] = "8";
@tds["9"] = "9"; @tds["0"] = "0";
# Symbols: Numbers Shift
@tds["!"] = "!"; @tds["@"] = "@"; @tds["#"] = "#"; @tds["$"] = "$";
@tds["%"] = "%"; @tds["^"] = "^"; @tds["&"] = "&"; @tds["*"] = "*";
@tds["("] = "("; @tds[")"] = ")";
# Symbols: Others
@tds["-"] = "-"; @tds["="] = "="; @tds["\\"] = "\\";
@tds["_"] = "_"; @tds["+"] = "+"; @tds["|"] = "|"
# First Set
@tds[","] = ","; @tds["."] = "."; @tds["/"] = "/";
@tds["<"] = "<"; @tds[">"] = ">"; @tds["?"] = "?"
# Second Set
@tds[","] = ","; @tds["."] = "."; @tds["/"] = "/";
@tds["<"] = "<"; @tds[">"] = ">"; @tds["?"] = "?"
# Third Set
@tds[";"] = ";"; @tds["'"] = "'"; @tds[":"] = ":";
# Fourth Set
@tds["["] = "["; @tds["]"] = "]"; @tds["{"] = "}"; @tds["{"] = "}"
# Make title graphic
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.title($data_system.title_name)
@sprite.y += 89
# Makes the help window
@help_window = Window_Help.new
@help_window.back_opacity = 160
# Makes the command window
@command_window = Window_Command.new(192, %w(Read Traduce Exit))
@command_window.back_opacity = 160
@command_window.x = 320 - @command_window.width / 2
@command_window.y = 288
# Make read window
@read_Window = Window_Base.new(0, 64, 640,64)
# Define windows bitmap size for content
@read_Window.contents = Bitmap.new(640-32, 32)
@read_Window.back_opacity = 160
# Defines a color for the windows content(system_color)
@read_Window.contents.font.color = Color.new(192, 224, 255, 255)
# Draws the content in the window.
@read_Window.contents.draw_text(0,0 + 5,640, 24, @tds_languaje_read.to_s,1)
# Make traduce window
@traduce_Window = Window_Base.new(0, 128, 640,64)
# Define windows bitmap size for content
@traduce_Window.contents = Bitmap.new(640-32, 32)
@traduce_Window.back_opacity = 160
# Play title BGM
$game_system.bgm_play($data_system.title_bgm)
# Stop playing ME and BGS
Audio.me_stop
Audio.bgs_stop
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@command_window.dispose
@help_window.dispose
@traduce_Window.dispose
@read_Window.dispose
# Dispose of title graphic
@sprite.bitmap.dispose
@sprite.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@command_window.update
@read_Window.update
@traduce_Window.update
@help_window.update
# Updates the contents of the help window depending on the cursor position
case @command_window.index
when 0 # Read
@help_window.set_text('Reads from the TDS Code and traduces it to normal',1)
when 1 # Traduce
@help_window.set_text('Changes the text to a TDS coded one',1)
when 2 # Quit
@help_window.set_text('Exit the program',1)
end
# If the key C[Enter] is pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @command_window.index
when 0 # Read
traduce(traducing = false)
when 1 # Traduce
traduce(traducing = true)
when 2 # Quit
exit
end
end
#--------------------------------------------------------------------------
# * Traducing Method
#--------------------------------------------------------------------------
def traduce(traducing = false)
# Clears the content of the windows
@traduce_Window.contents.clear
@read_Window.contents.clear
# Traducing Variable
@traducing = traducing
# Draws the content in the window.
@read_Window.contents.draw_text(0,0 + 5,640, 24, @tds_languaje_read.to_s,1)
# Splitting the text into an array of each letter to be read later
@tds_languaje_traducing = @tds_languaje_read.split(//)
# Array for the ending traduction(what is being traduced into the @tds laungaje)
@tds_languaje_end_traduction = []
# Array for starting to traduce(What is bein traduced from the @tds languaje)
@tds_languaje_start_traduction = []
for i in 0...@tds_languaje_traducing.size
@tds_languaje_start_traduction << @tds.index(@tds_languaje_traducing[i])
@tds_languaje_end_traduction << @tds.indexes(@tds_languaje_traducing[i]).to_s
end
if @traducing == false
# Draws the content in the window.
@traduce_Window.contents.draw_text(0,0 + 5,640, 24, @tds_languaje_start_traduction.to_s,1)
else
@traduce_Window.contents.draw_text(0,0 + 5,640, 24, @tds_languaje_end_traduction.to_s,1)
end
# Opnes the text file to wrrite in it or creates one
File.open('tds Languaje Write.txt',"a+") do |file_write|
# Writes the text translated languaje to the file
if @traducing == true
file_write.puts(@tds_languaje_end_traduction.to_s + " - Traduced to TDS Languaje Code")
else
file_write.puts(@tds_languaje_start_traduction.to_s + " - Traduced from TDS Languaje Code")
end
end
end
end
#==============================================================================
# ** Main
#------------------------------------------------------------------------------
# After defining each class, actual processing begins here.
#==============================================================================
begin
# Prepare for transition
Graphics.freeze
# Make scene object (title screen)
$scene = Scene_TDS_Languaje.new
# Call main method as long as $scene is effective
while $scene != nil
$scene.main
end
# Fade out
Graphics.transition(20)
rescue Errno::ENOENT
# Supplement Errno::ENOENT exception
# If unable to open file, display message and end
filename = $!.message.sub("No such file or directory - ", "")
print("Unable to find file #{filename}.")
end
end
For this you will need to make a .txt file inside the game folder with the name "TDS Languaje Read" Without the "", and inside that file you have to put the words you wish to translate into the coded version. After that go to the other file "TDS Languaje Write" without the "" that is automatically created and open it to see the coded version of your text.
Well thanks for reading and for any feedback on it.