Searching a file and comparing information
by Phil Herrin · in Torque Game Engine Advanced · 07/06/2008 (9:19 pm) · 3 replies
Having some trouble figuring out how to search a text file for a bit of info and the compare it to the input
file format
username password
username password
username password
username password
how do i search for a certain username and the compare the given password with the text file password?
and would it be easier to make the format
username bob password test so that i can search and compare easier? and add to it later such as
username bob password test strength 10 agility 10 arrows 10 position 100,100
etc?
part 2 of the question is how to implement a main gui that takes 2 guitext boxes as the input for comparing and if there is a match, loads a mission with the players name as the username etc
and if there is no match, takes the user to a screen to create a name?
file format
username password
username password
username password
username password
how do i search for a certain username and the compare the given password with the text file password?
and would it be easier to make the format
username bob password test so that i can search and compare easier? and add to it later such as
username bob password test strength 10 agility 10 arrows 10 position 100,100
etc?
part 2 of the question is how to implement a main gui that takes 2 guitext boxes as the input for comparing and if there is a match, loads a mission with the players name as the username etc
and if there is no match, takes the user to a screen to create a name?
About the author
#2
As for saving/loading XML files, there *should* be a file called "xml.cs" somewhere in your project directory. This file contains various functions needed to save and load XML type files. If you open 'er up and have a gander at the functions themselves, you should learn a lot.
07/06/2008 (11:16 pm)
I suggest that you look into using XML files or load information from a database. I haven't had any experience in the latter, however, I believe there are a number of resources available which deal with this.As for saving/loading XML files, there *should* be a file called "xml.cs" somewhere in your project directory. This file contains various functions needed to save and load XML type files. If you open 'er up and have a gander at the functions themselves, you should learn a lot.
#3
- File format
As long as you keep the individual fields in a set order, you don't need key/value pairs. Just write out each individual value and read them in in the same order.
To at least make the cheapest form of cheating more difficult, you could run each line through an encryption function.
- Go to specific line in file
Only works with fixed-width lines as otherwise there's no way to predict the offset of a given line.
07/07/2008 (2:33 pm)
- Match up username$stream = new FileStreamObject();
$stream.open( "users.dat", "read" );
while( !$stream.isEOF() )
{
%line = $stream.readLine();
if( getWord( %line, 0 ) == $UserNameYouAreLookingFor )
{
;//Do your thing here (match password, etc)
break;
}
}- File format
As long as you keep the individual fields in a set order, you don't need key/value pairs. Just write out each individual value and read them in in the same order.
To at least make the cheapest form of cheating more difficult, you could run each line through an encryption function.
- Go to specific line in file
Only works with fixed-width lines as otherwise there's no way to predict the offset of a given line.
Torque Owner Phil Herrin
username
password
strength
charisma
experience
level
etc
ie if line1 = user entered username AND if line 2 = user entered password then load mission as that user and set the variables to the rest of the text file ie playerstrength = strength etc