Author Topic: Help with .ini  (Read 1715 times)

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Help with .ini
« on: November 20, 2012, 10:45:18 pm »
Hello

I'm making a language system using an ini file, in this way:

Code: [Select]
[Test]
esp = "Esto es un test"
eng = "This is a test"

In VRocker's area system, he uses many strings in a single "title", so my ini would be like this:
Code: [Select]
[Langs]
Test = "Esto es un test", "This is a test"
How to read sections of the same "title"?

Thanks
« Last Edit: December 08, 2012, 10:36:49 pm by IdkanYavuk »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 526
  • Karma: +27/-17
    • View Profile
Re: Help with .ini
« Reply #1 on: November 23, 2012, 09:40:03 pm »
Use a seperator that wont be used in any lines of text, like ; .
You make your ini like this:
Code: [Select]
[Langs]
Line1="Esto es un test;This is a test"

To get the correct language lines, use this:
Code: [Select]
local Lang1 = ReadIniString( "Langs.ini", "Langs", "Line1" );
local esp = GetTok( Lang1, ";", 0 ); //This will get the first part of the whole line, untill the first ; is found
local eng = GetTok( Lang1, ";", 1 ); //You can probably fill in what this thing does here..

Hope that helps you out.

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Re: Help with .ini
« Reply #2 on: November 24, 2012, 12:25:01 am »
Thanks! But if I want more languages?

I use this?:

Code: [Select]
local fra = GetTok( Lang1, ";", 2 );


Another thing: what if I want variables in those messages? for example

Quote
"Bienvenido al server, " + plr
"Welcome to the server, " + plr
« Last Edit: December 08, 2012, 10:36:24 pm by IdkanYavuk »

morphine

  • Newbie
  • *
  • Posts: 9
  • Karma: +2/-0
    • View Profile
Re: Help with .ini
« Reply #3 on: November 24, 2012, 11:07:26 am »
Thanks! But if I want more languages?

I use this?:

Code: [Select]
local fra = GetTok( Lang1, ";", 2 );

Yeah.


Quote
Another thing: what if I want variables in those messages? for example

Quote
"Bienvenido al server, " + plr
"Welcome to the server, " + plr

You would just have to extract the text from the ini and then attach the player's name/whatever to it in a callback such as onPlayerJoin.

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 526
  • Karma: +27/-17
    • View Profile
Re: Help with .ini
« Reply #4 on: November 25, 2012, 08:57:38 pm »
You could use two way.

First:
Store a string that you will place before the player. Something like "Welcome to the server, "
Then store a string you would like to place behind it, in this case it will be nothing.
Then on your signal paste your player name behind the first bit and paste the behind-stuff behind that.

Second:
Store your messages like this:
"Welcome to the server, %plr%"

Then on your join signal you do something like this:
Code: [Select]
local lang = ReadIniString( "Langs.ini", "Langs", "Line1" );
lang = GetTok( lang, ";", 1 );
lang = Replace( lang, "%plr%", plr.Name );
MessagePlayer( lang, plr );

and the function:
Code: [Select]
function Replace( szOriginal, szFind, szReplace )
{
local iCharPos = szOriginal.find( szFind );
local iLength = szFind.len();

local szBefore = szOriginal.slice( 0, iCharPos );
local szBehind = szOriginal.slice( ( iCharPos + iLength ) );

return ( szBefore + szReplace + szBehind );
}
You could of course add more variables that way, Just add more %vars% and copy the Replace line.

Function is tested, rest is not. Good luck ;)

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Re: Help with .ini
« Reply #5 on: November 25, 2012, 09:26:48 pm »
Wow! nice! thanks Thijn!
Thanks all
« Last Edit: December 08, 2012, 10:35:56 pm by IdkanYavuk »

 

© Liberty Unleashed Team.