Aller au contenu

Photo

Reading from a text file


  • Veuillez vous connecter pour répondre
5 réponses à ce sujet

#1
RPGBL777

RPGBL777
  • Members
  • 13 messages
Hi guys,

Is there anyway to read text from .txt file ? For example : I have this contents :

- content 1
- content 2
- content 3

and all I want to do is to get the last line of the content (only "content 3")

Any sugestions please? Thanks

#2
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages
Hi RPGBL777,

It would probably be easier to say what you are trying to do with respect to the game rather than what you are trying to do specifically.

For example, there are ways to retrieve text from include scripts, objects or 2da files. Depending on how much text you want to access and how often may determine the best route to take. There may even be other ways to do exactly what you want, but I do not know them.

I believe there is a utility on the Vault that allows a player to use the Player's Handbook in a game (as an example), which may do more what you are after. However, I have been unable to find this and so wonder if I am mistaken. Found the link I was thinking of (not sure if it helps or not): Player Handbook.

Lance.

Modifié par Lance Botelle, 21 juillet 2010 - 03:17 .


#3
c i p h e r

c i p h e r
  • Members
  • 261 messages
I don't believe it can read .TXT files, but it can read .2DA files which contain text strings.

string Get2DAString(string s2DA, string sColumn, int nRow)

Where s2DA is the 2DA file on your server. You'll need to make sure you adhere to the 2DA format for this function to work (just copy an existing 2DA file and edit it for your purposes). The file name may be limited to 16 or 32 chars. Also, I think there was a character limit of 255 chars per field, so just something to keep in mind. Don't go bonkers. :)

Modifié par ç i p h é r, 21 juillet 2010 - 09:08 .


#4
RPGBL777

RPGBL777
  • Members
  • 13 messages
hi guys thanks for the replies. I was asking because actually I want to extract the error message generated from mySQL. Im using NWNX and I was hoping that I can show the error message sent by mysql for any query error.



In default, all the query errors is recorded in the mysql.txt so Im just wondering if i can just retrieve the last line of the mysql.txt (the error msg is accumulated in the txt file)

#5
c i p h e r

c i p h e r
  • Members
  • 261 messages
There is no NWN2 command for this, but there may be an NWNX command or plugin you could use. Try asking on the NWNX forums.

#6
.Lv

.Lv
  • Members
  • 6 messages
If I remember correctly you can get the sql error number and message by query to the mysql plugin.
There :

string SQLGetErrorMessage()
{
   return NWNXGetString("SQL", "GET ERROR MESSAGE", "", 0);
}
int SQLGetErrorNumber()
{
   return NWNXGetInt("SQL", "GET ERRNO", "", 0);
}


By looking at the nwnx source code it seems those are still registered string query. Anyway you can try them, it does not cost much.

Modifié par .Lv, 06 août 2010 - 07:50 .