PDA

View Full Version : Retrieving User Stats


stuntguy3000
5th October 2010, 23:37
Hello,
On my Cruise Insim you can buy flowers and toys and sell them at houses.
That works and the selling also works. I want to make it that you can leave the server and re join and still have your flowers/toys. When you leave my server It Does save the flower/toy stats in the user.txt file but when you join it won't fetch that data.

static public int GetUserFlowers(string Username)
{
StreamReader Sr = new StreamReader(UserInfo + "\\" + Username + ".txt");

string line = null;
while ((line = Sr.ReadLine()) != null)
{
if (line.Substring(0, 6) == "Flowers")
{
string[] Msg = line.Split('=');
Sr.Close();
return int.Parse(Msg[1].Trim());
}
}
Sr.Close();
return 0;
}

Also this is my User File BTW

WORKS - Cash = 495031
WORKS - BBal = 1000
WORKS - Cars = UF1 XFG
WORKS - Distance = 1002441
WORKS - Health = 100
WORKS - Stat = 1
DOESN'T WORK - Flowers = 20
DOESN'T WORK - Toys = 0
DOESN'T WORK - JobsCompleted = 0
DOESN'T WORK - JobsAccepted = 0
DOESN'T WORK - FlowersSold = 0
DOESN'T WORK - ToysSold = 0

By DOESN'T WORK it saves it like i said but it won't read it and apply it to the users flowers etc on the server.

I am using LFS_External

Thanks

amp88
5th October 2010, 23:45
if (line.Substring(0, 6) == "Flowers")


http://bytes.com/topic/c-sharp/answers/762995-string-equals

stuntguy3000
6th October 2010, 00:20
http://bytes.com/topic/c-sharp/answers/762995-string-equals

Thanks, I am pretty much a newbie with Insim/C# Coding so i can't really understand anything of the stuff in that link.

Do you think you could maybe provide an example plz.

Thanks!

stuntguy3000
6th October 2010, 00:23
Ok. It works now - well i think.

How can i set the flowers in the user file to the C.Flowers Byte?????

amp88
6th October 2010, 00:28
After some Looking and Studying the code i realized what to change.

Good.

Thanks for the other help tho!

You're welcome.

stuntguy3000
6th October 2010, 00:53
Good.



You're welcome.

Hang On.. LOL

It still won't retrieve the stats. Or how do i tell it to put the thing in the Connectionsfgbzdfgbfgb.Flowers Byte Thing?

skywatcher122
6th October 2010, 02:53
did u forget the NewConn to load those ints?

stuntguy3000
6th October 2010, 05:53
did u forget the NewConn to load those ints?

OMG Thanks so Much you ROCK!

lolage...

broken
6th October 2010, 09:14
if (line.Substring(0, 6) == "Flowers")



line.Substring(n, 6) will never equal "Flowers"

Dygear
6th October 2010, 09:31
When is that ever useful in a language? That just seems to be overtly obtuse and for no reason then to just be obtuse! This is another area that I feel that PHP excels, comparing data. == checks that the bits are the same, whereas === checks that the bits and the data type are the same.

skywatcher122
6th October 2010, 09:59
What amp88 said.
line.Substring(n, 6) will never equal "Flowers"

its suppose to be

F L O W E R S
1 2 3 4 5 6 7 :x?

DarkTimes
6th October 2010, 10:00
When is that ever useful in a language? That just seems to be overtly obtuse and for no reason then to just be obtuse! This is another area that I feel that PHP excels, comparing data. == checks that the bits are the same, whereas === checks that the bits and the data type are the same.

Well the reason it won't work is because "Flowers" is seven characters in length, but he's only checking the first six characters of the substring.

Substring has its uses, mainly for slicing ranges out of strings, but in C# you would normally do:

if (line.StartsWith("Flowers"))
{

}

Or if you're worried about internationalisation:

if (line.StartsWith("Flowers", StringComparison.InvariantCulture))
{

}

C# doesn't need '===' because it is strongly typed. We have '==' for reference comparison and 'is' for type comparison.

broken
6th October 2010, 10:23
What amp88 said.
line.Substring(n, 6) will never equal "Flowers"

its suppose to be

F L O W E R S
1 2 3 4 5 6 7 :x?

Have you passed first grade yet? Can you make difference between the numbers? :tilt:

Go ask your application if it sees Flowers in 6 letters. I think it sees Flower. Go and wonder why it doesn't want to find your Flowers then. :razz:

skywatcher122
6th October 2010, 10:26
i know about it :P
just some trollers do

stuntguy3000
6th October 2010, 22:20
Have you passed first grade yet? Can you make difference between the numbers? :tilt:

Go ask your application if it sees Flowers in 6 letters. I think it sees Flower. Go and wonder why it doesn't want to find your Flowers then. :razz:

FAIL - that doesn't solve the problem for the other ones.

Toys
JobsCompleted
JobsAccepted
ToysSold
FlowersSold

stuntguy3000
7th October 2010, 00:08
I HAVE STARTED A NEW INSIM.
Its Still LFS_External. When i add the JobsCompleted Thing nothing works. no hud/commands work.

i need to
//NewConn.JobsCompleted = FileInfo.GetUserJBS_Completed(NCN.UName);

to get the insim to work? HELP!

static public int GetUserJBS_Completed(string Username)
{
StreamReader Sr = new StreamReader(UserInfo + "\\" + Username + ".txt");

string line = null;
while ((line = Sr.ReadLine()) != null)
{
if (line.Substring(0, 14) == "Jobs Completed")
{
string[] Msg = line.Split('=');
Sr.Close();
return int.Parse(Msg[1].Trim());
}
}
Sr.Close();
return 0;
}

broken
7th October 2010, 07:06
Sorry, but I helped you and all you seemed to say back to me was "FAIL". Don't expect anything more from me. ;)

On top of that, if you follow the logic, it will work. But maybe you're lacking common sense, and that, I can not fix.

skywatcher122
7th October 2010, 12:07
its like tomatoes and potatoes...I'll end up this supporting since you are lacking some common sense (no offense)

91mason91
7th October 2010, 12:25
its like tomatoes and potatoes...I'll end up this supporting since you are lacking some common sense (no offense)

:really:

Dygear
8th October 2010, 03:47
Well the reason it won't work is because "Flowers" is seven characters in length, but he's only checking the first six characters of the substring.

So, then a more helpful answer in the first place would be that the string length of Flowers is not 6, but 7.

Substring has its uses, mainly for slicing ranges out of strings, but in C# you would normally do:

if (line.StartsWith("Flowers"))
{

}

Or if you're worried about internationalisation:

if (line.StartsWith("Flowers", StringComparison.InvariantCulture))
{

}

I think the StartsWith one would work better, in this case at least. I assume there is an EndsWith as well? Is there a good online resource for looking this information up that might be a good to post so people can help them self first, and ask questions later? (That's really not a bad idea, start a programming resource thread for all of the languages.)

C# doesn't need '===' because it is strongly typed. We have '==' for reference comparison and 'is' for type comparison.

Yeah, I was not quite groking that it should of been 7 not 6 in the first place, and I thought that you could not check the string object against just a string without some extra vodo.

DarkTimes
8th October 2010, 09:38
Is there a good online resource for looking this information up that might be a good to post so people can help them self first, and ask questions later?

Yes, it's called MSDN (http://msdn.microsoft.com/en-us/library/ms229335.aspx). Here is the System.String (http://msdn.microsoft.com/en-us/library/system.string.aspx) class.

Note in Visual Studio if you place your mouse over a class and press F1 it will take you to the documentation for that object automatically.

joordy599
8th October 2010, 12:06
im a friend of stuntguy3000 but i need hes help i can change only some things