Using external files (txt or xml) to a reposisotry of phrases

Started by sgreco, Sat 29/05/2010 11:28:02

Previous topic - Next topic

sgreco

Hi all ,
my pourpose is to use a external text file ( a simple txt or a xml ) where i can create a repository for a phrases to use in-game.

I mean,

instead of
----------------------------
Character.say("Hello");

i want to use something like
-----------------------------------------
String mystr = MyReadFunction()
Character.Say(mystr);

How can i structure external file?
There is some plugin who permit me to use xml structure?

My scope is to externalize all the phrases (used for a examine a object, for example) actually write into code

Thanks to all :)


Khris

May I ask the reason for that?

If you don't encrypt the file, anybody could alter the messages.

sgreco

Quote from: Khris on Sat 29/05/2010 11:52:05
May I ask the reason for that?

If you don't encrypt the file, anybody could alter the messages.

above all other games have an external file dialogues \ phrases (see A vampyre story).
and then I prefer to have an external file for 2 simpe reason :

1 - the basics of software programming is inadvisable to use values in the code.
values must always be set outside the code (in this case, the values correspond to the phrases that the character should say

2 - Imagine having to do a translation of your game. How do you manage it?
I do not think you want to go line by line in code to search for phrases to be translated :)

Sslaxx

Quote from: sgreco on Sat 29/05/2010 14:13:42
2 - Imagine having to do a translation of your game. How do you manage it?
I do not think you want to go line by line in code to search for phrases to be translated:)
But you don't have to, you can get AGS to do that for you! It'd save you half of the legwork (by finding strings of text that need to be translated).
Stuart "Sslaxx" Moore.

sgreco

Quote from: Sslaxx on Sat 29/05/2010 14:17:59
Quote from: sgreco on Sat 29/05/2010 14:13:42
2 - Imagine having to do a translation of your game. How do you manage it?
I do not think you want to go line by line in code to search for phrases to be translated:)
But you don't have to, you can get AGS to do that for you! It'd save you half of the legwork (by finding strings of text that need to be translated).

Ok, maybe this is a solution, but not the better i think :) in 50% of cases, translation made by an automatico tool is always cheap.
By the way, i repeeat my question..
somebody know some kind of a module, script o way to manage this ?

thanks

Sslaxx

Quote from: sgreco on Sat 29/05/2010 15:03:15
Quote from: Sslaxx on Sat 29/05/2010 14:17:59
Quote from: sgreco on Sat 29/05/2010 14:13:42
2 - Imagine having to do a translation of your game. How do you manage it?
I do not think you want to go line by line in code to search for phrases to be translated:)
But you don't have to, you can get AGS to do that for you! It'd save you half of the legwork (by finding strings of text that need to be translated).

Ok, maybe this is a solution, but not the better i think :) in 50% of cases, translation made by an automatico tool is always cheap.
The point is, it doesn't do the translation for you - it finds all the strings of text that can be translated.
Stuart "Sslaxx" Moore.

sgreco

Quote from: Sslaxx on Sat 29/05/2010 15:15:16
Quote from: sgreco on Sat 29/05/2010 15:03:15
Quote from: Sslaxx on Sat 29/05/2010 14:17:59
Quote from: sgreco on Sat 29/05/2010 14:13:42
2 - Imagine having to do a translation of your game. How do you manage it?
I do not think you want to go line by line in code to search for phrases to be translated:)
But you don't have to, you can get AGS to do that for you! It'd save you half of the legwork (by finding strings of text that need to be translated).

Ok, maybe this is a solution, but not the better i think :) in 50% of cases, translation made by an automatico tool is always cheap.
The point is, it doesn't do the translation for you - it finds all the strings of text that can be translated.

ok, but the translation is a consequence of what I do.

My primary purpose is to manage an external file as repositorydi sentences.
For example all the "Examine" facts about the objects of a room.
I do not like them in the code, and I want them outside.

CShelton

In professional game development, dialogue, recorded speech, and assets with written text (signs, etc) are always externalized for localization purposes. So instead of arguing about whether this method is right or wrong for AGS, can someone answer the technical portion of if it is possible?

Gilbert

The problem is, current File reading/writing support in AGS is a bit limited (unless you use a plugin), that random access is not possible, i.e. if you need to read-from/write-to a certain location of a file at random time in the game you'll need to go from the beginning and read/write the file sequentially until the required information is reached.

One work around is to read everything and parse the content when the game starts, but you'll need to allocate enough memory for holding this information for the course of the game.

AJA

Our game project (see picture below) uses a system that works something like this:

Every room has a separate text file for speech text, a sort of a very limited custom scripting language, formatted in separate blocks like this

Code: ags
# ACTION-TITLE
  roger: Your hair looks fabulous!
  larry: Thanks, I grew it myself.
  wait: 40
  walk: roger, 160, 100
}


Then upon entering a room a module sets the current read-file to the room's file and after that you can call readLines("ACTION-TITLE") which reads through the file and finds the piece of script with that title and parses and runs it line by line. And since every room has its own file, the files are shorter and thus faster to read through. It's not exactly what you're asking for but it's quite useful. We took this feature out of our game's demo and converted the scripts into AGS scripts to hide the content but hopefully we can upgrade the system somehow before the final release of the game and keep the content separated from AGS.

sgreco

Quote from: AJA on Sun 30/05/2010 12:08:16
Our game project (see picture below) uses a system that works something like this:

Every room has a separate text file for speech text, a sort of a very limited custom scripting language, formatted in separate blocks like this

Code: ags
# ACTION-TITLE
  roger: Your hair looks fabulous!
  larry: Thanks, I grew it myself.
  wait: 40
  walk: roger, 160, 100
}


Then upon entering a room a module sets the current read-file to the room's file and after that you can call readLines("ACTION-TITLE") which reads through the file and finds the piece of script with that title and parses and runs it line by line. And since every room has its own file, the files are shorter and thus faster to read through. It's not exactly what you're asking for but it's quite useful. We took this feature out of our game's demo and converted the scripts into AGS scripts to hide the content but hopefully we can upgrade the system somehow before the final release of the game and keep the content separated from AGS.
Thanks AJa. I think this is the better solution, instead to have a big-enormous file for ALL the rooms.

Now my question is, How you can make a search into the file ?
for example,

i've in Room 1 two objects.
i suppose that on my "Room1.txt" file i need to have :

..
# Room1
object1= "This is a cup of coffee"
object2= "This is a cup of tea"
...

Now,
Somebody can post some example code that i integrate into my project, in order to read these phrases , and use these when i click "Examine-the-object" ? :)

Thanks a lot to all :)

AJA

This should work...


Module header:
Code: ags

#define PHRASE_DIR "phrasefiles"
import void setPhraseFile( String filename );
import String getPhrase( String phrase );


Module:
Code: ags

// new module script
String phraseFile;

// Trims whitespace
String Trim( this String* )
{
  int start = 0;
  while ( start < this.Length &&
        ( this.Chars[start] == eKeySpace || this.Chars[start] == eKeyTab ) )
    start++;
  
  int end = this.Length - 1;
  while ( end > start &&
        ( this.Chars[end] == eKeySpace || this.Chars[end] == eKeyTab ) )
    end--;
  
  return this.Substring( start, end - start + 1 );
}

void setPhraseFile( String filename )
{
  phraseFile = filename;
}

String getPhrase( String phrase )
{ 
  String filename = String.Format( "%s/%s", PHRASE_DIR, phraseFile );
  File* f = File.Open( filename, eFileRead );
  if ( f == null )
    AbortGame( "Could not open phrase file: %s!", phraseFile );
  
  // Read all the lines until we find the correct phrase
  while ( !f.EOF )
  {
    String line = f.ReadRawLineBack();
    
    // Skip empty lines and comments
    if ( !(line.Length == 0 || line.StartsWith( "#" )) )
    {
      // Split line
      int splitPoint = line.IndexOf( ":" );
      if ( phrase.CompareTo( line.Substring( 0,  splitPoint ) ) == 0 )
      {
        // Found!
        f.Close();
        line = line.Substring( splitPoint + 1,  line.Length - splitPoint - 1 );
        return line.Trim();
      }
    }
  }
  
  // Not found!
  f.Close();
  Display( "Phrase \"%s\" not found in file %s!", phrase, phraseFile );
  return "";
}



room1.txt in subdirectory "phrasefiles"
Code: ags

# Comment.. object phrases go here:
object1: This is a cup of coffee.
object2: This is a cup of tea.

# Something else goes here



Usage:
Code: ags

// Enters room:
setPhraseFile( "room1.txt" );

// Interaction:
cEgo.Say( getPhrase( "object1" ) );



edit:
Bug fixed.

sgreco

Woho!
It work great!

This was exaclty what i looking for!
Really, really thanks, AJA to sharing your knowledge with me!



SMF spam blocked by CleanTalk