[XP] Text database

Started by Wingard, June 05, 2014, 11:27:18 am

Previous topic - Next topic

Wingard

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:   :)

Soulshaker3

June 05, 2014, 12:25:22 pm #1 Last Edit: June 05, 2014, 12:28:13 pm by soulshaker3
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
Hellow?

KK20

How does this one not satisfy your needs? You get strings with a \loc[id] call.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Wingard

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:

Soulshaker3

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
Hellow?

Wingard

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.

ForeverZer0

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
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

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.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ForeverZer0

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.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

Shouldn't it be [Ll][Oo][Cc] and not [Tt][Dd]? xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Wingard

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"  ;)

ForeverZer0

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.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Wingard

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! :)

LiTTleDRAgo

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)

Wingard

June 25, 2014, 04:23:48 pm #14 Last Edit: June 25, 2014, 04:26:52 pm by Wingard
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. :)

KK20

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

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Wingard


KK20

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)

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Wingard

It works now! Thank you very much  :D