Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Wingard on June 05, 2014, 11:27:18 am

Title: [XP] Text database
Post by: Wingard on June 05, 2014, 11:27:18 am
Hello!  :D  Ive looked through many scripts (mostly for localisation and making the game multi-language) but i couldnt find the one i need. I think its a simple one to do but my total lack of Ruby knowledge makes me ask for it here.  :)

What i mean is a Text database script. You know how we can summon the Actors name to the message via the \n[ ] command, right? (some scripts even allow to summon item's or skill's name like UMS). Id like to have this working for the texts stored in this Database script. Like this:

1 = "Aluxes loves Gloria"
2 = "Marco is jealous"
etc.

and then in the message box or choice box we type the \td[1] command which would make the quote "Aluxes loves Gloria" appear in place of it. And thats all!

So, could anyone do this? Pretty please?  :plz:   :)
Title: Re: [XP] Text database
Post by: Soulshaker3 on June 05, 2014, 12:25:22 pm
That is already done in this link http://forum.chaos-project.com/index.php/topic,10828.0.html just read the instructions and you should be good to go.

Edit; Okay forget what i said, that thing is dead that perhaps somebody has it arround
Title: Re: [XP] Text database
Post by: KK20 on June 05, 2014, 02:44:50 pm
How does this one (http://forum.chaos-project.com/index.php/topic,12164.0.html) not satisfy your needs? You get strings with a \loc[id] call.
Title: Re: [XP] Text database
Post by: Wingard on June 05, 2014, 03:37:18 pm
Quote from: KK20How does this one not satisfy your needs? You get strings with a \loc[id] call.

Texts are coming from the external file which can be edited by the player and which is not getting compressed along with the rest of the project's resources. :(
Other than that its good. I'll use it if no one will be willing to make the one im asking for.  :shy:
Title: Re: [XP] Text database
Post by: Soulshaker3 on June 05, 2014, 05:36:09 pm
Quote from: Wingard on June 05, 2014, 03:37:18 pm
Quote from: KK20How does this one not satisfy your needs? You get strings with a \loc[id] call.

Texts are coming from the external file which can be edited by the player and which is not getting compressed along with the rest of the project's resources. :(
Other than that its good. I'll use it if no one will be willing to make the one im asking for.  :shy:


You can always use an encrypting system that does it for all the files in the project
Title: Re: [XP] Text database
Post by: Wingard on June 05, 2014, 06:07:36 pm
Quote from: soulshaker3 on June 05, 2014, 05:36:09 pm
You can always use an encrypting system that does it for all the files in the project


True, but having texts in the script would allow user to use ruby commands to influence them! For example conditional branch with the variable would mean many quotes for one ID, and in game we would see only the one that matches the condition.
Well, technically its doable in maker as well... but i just prefer to have all texts in one place, inside the project.
Title: Re: [XP] Text database
Post by: ForeverZer0 on June 06, 2014, 06:29:37 am
Here's a super quick, untested script.

Define the "STRINGS" constant with your text, and that's about all you need to do.  From there all you need to do is use the "\td[ID]" tags anywhere you like to, it can even be in the editor, and it will display in-game correctly.

Spoiler: ShowHide
#===============================================================================
# ** TextDatabase
#===============================================================================

module TextDatabase
 
  STRINGS = {
    nil => '',
    1 => "Aluxes loves Gloria",
    2 => "Marco is jealous"
  }

  def self.parse(string)
    if string.is_a?(String)
      return string.gsub(/\\[Tt][Dd]\[(.+)\]/) { STRINGS[$1.to_i] }
    end
    return string
  end
end

#===============================================================================
# ** Game_Temp
#===============================================================================

class Game_Temp
  def message_text=(string)
    @message_text = TextDatabase.parse(string)
  end
end

#===============================================================================
# ** Bitmap
#===============================================================================

class Bitmap
  alias textdatabase_draw_text draw_text
  def draw_text(*args)
    args.each_index {|i|
      args[i] = TextDatabase.parse(args[i]) if args[i].is_a?(String) }
    textdatabase_draw_text(*args)
  end
end
Title: Re: [XP] Text database
Post by: Blizzard on June 06, 2014, 07:18:53 am
You should use strings for keys. In case of localizations it's much easier to overview things and edit stuff later when strings are used for keys. I speak from years of experience.
Title: Re: [XP] Text database
Post by: ForeverZer0 on June 06, 2014, 07:48:29 am
Quote from: Blizzard on June 06, 2014, 07:18:53 am
You should use strings for keys. In case of localizations it's much easier to overview things and edit stuff later when strings are used for keys. I speak from years of experience.


In that case, the only edit that needs done is to change this line:
return string.gsub(/\\[Tt][Dd]\[(.+)\]/) { STRINGS[$1.to_i] }


to...
return string.gsub(/\\[Tt][Dd]\[(.+)\]/) { STRINGS[$1] }


...and of course use strings for the keys instead of numbers.
Title: Re: [XP] Text database
Post by: Blizzard on June 06, 2014, 09:38:05 am
Shouldn't it be [Ll][Oo][Cc] and not [Tt][Dd]? xD
Title: Re: [XP] Text database
Post by: Wingard on June 06, 2014, 05:35:18 pm
Yaay, it works! And the idea of strings instead of numbers is indeed better.

Thank you very much! :D

QuoteShouldn't it be [Ll][Oo][Cc] and not [ Tt][Dd]? xD

"td" as in "Text Database"  ;)
Title: Re: [XP] Text database
Post by: ForeverZer0 on June 07, 2014, 06:42:16 am
Quote from: Blizzard on June 06, 2014, 09:38:05 am
Shouldn't it be [Ll][Oo][Cc] and not [Tt][Dd]? xD


Erase a few methods. Add a constant. Rename. Done.
Title: Re: [XP] Text database
Post by: Wingard on June 25, 2014, 02:00:24 pm
Um, hi  :D , id like to refresh this topic to ask about one thing: would it be possible to make texts from the Text database usable in other scripts? I want to display quotes in few rgss windows of my project. Alot of use can be made of this script right now but adding such feature would greately improve it's overall usefulness! :)
Title: Re: [XP] Text database
Post by: LiTTleDRAgo on June 25, 2014, 03:11:42 pm
something like this?

s1 = TextDatabase.parse('Okay')
s2 = TextDatabase.parse('Cancel')
@command = Window_Command.new(180,[s1,s2])


text = TextDatabase.parse('Equipment')
self.contents.draw_text(0,290,200,32,text,2)
Title: Re: [XP] Text database
Post by: Wingard on June 25, 2014, 04:23:48 pm
Quote from: LiTTleDRAgosomething like this?

Um, not exactly. Dont know if i understood correctly but if my text database looks like this:

module TextDatabase
 
 STRINGS = {
   nil => '',
   "AxG" => "Aluxes loves Gloria",
   "MiJ" => "Marco is jealous",
   "Okay" => "Okthisyeah",
 }


then command
s1 = TextDatabase.parse('Okay')

displays the word "Okay" instead of "Okthisyeah". Same about
text = TextDatabase.parse('Okay')
self.contents.draw_text(0,290,200,32,text,2)


The idea is to have this showing the quote, not it's ID. :)
Title: Re: [XP] Text database
Post by: KK20 on June 25, 2014, 04:36:01 pm
text = "\td['Okay']"
self.contents.draw_text(0,290,200,32,text,2)
Title: Re: [XP] Text database
Post by: Wingard on June 25, 2014, 04:57:49 pm
Still no   D:
(http://s30.postimg.org/w4ahua97j/okay.jpg)
Title: Re: [XP] Text database
Post by: KK20 on June 25, 2014, 05:15:34 pm
I always get my single and double quotes mixed up when it comes to backslashes...

Double Quotes:
text = "\\td[Okay]"
self.contents.draw_text(0,290,200,32,text,2)

Single Quotes:
text = '\td[Okay]'
self.contents.draw_text(0,290,200,32,text,2)
Title: Re: [XP] Text database
Post by: Wingard on June 25, 2014, 05:21:13 pm
It works now! Thank you very much  :D