The online racing simulator
!send command [Help Needed]
1
(31 posts, closed, started )
#1 - sun
!send command [Help Needed]
Hello,
I've com accross somthing what i was really supposed of figured out.
Its the !send command. i know how to do others, but not this, i know that it goes out of your account like the !buy, but Transffering into other peoples accounts.

If any one can help please post in here, or Explain what i'am supposed to know or do.

Thanks,

Regards

Owen.


-----------------------------

Owner of:

Owens Cruise Server

-----------------------------
Quote from sun :Hello,
I've com accross somthing what i was really supposed of figured out.
Its the !send command. i know how to do others, but not this, i know that it goes out of your account like the !buy, but Transffering into other peoples accounts.

If any one can help please post in here, or Explain what i'am supposed to know or do.

Thanks,

Regards

Owen.


-----------------------------

Owner of:

Owens Cruise Server

-----------------------------

You need to learn how to code... that's all :P
Quote from eight8acht :You need to learn how to code... that's all :P

Exactly, but for some insane reason. He wont.
#4 - vane
I have had great fun learning to code, i may be wrong but am i the only "crazed guy who wants to make a cruise server" who has bothered to try and learn? except of course for bose
#5 - sun
OMG I 'am bothered to learn how to code... omg i cant say because i can code, i can make windows games (little) i can make applications, but when it comes to !send command its all of topic, So STOP THAT STUFF! FOR THE LAST TIME !
Quote from sun :OMG I 'am bothered to learn how to code... omg i cant say because i can code, i can make windows games (little) i can make applications, but when it comes to !send command its all of topic, So STOP THAT STUFF! FOR THE LAST TIME !

What's so difficult to understand?

Check to see if the user has the available 'funds' - If he has then add them to the user he is sending them to and deduct it from his 'funds' what else is there?

P.S : From what I've seen of all your previous threads, my guess is you know little to nothing about developing code, but I'm sure you're well aware of that.
Quote from Rooble :I'm sure you're well aware of that.

If only...

My advice (which will either be ignored, or have to be explained), is to use a foreach loop that looks for the specified Username (from the !send command) and then adds the specified cash (also from the !send command) to their cash, at the same time, subtracting the specified cash from the person who typed the command...

Without explaining each tiny process there, that's as simple as it can be said. If you can't even make a reasonable attempt at that, there is no hope. I'm not knocking you, that's just fact. (Besides the fact that Google has much better answers than the LFS forum...)
#8 - sun
yer, thanks dougie i'll give it a go
#9 - sun
!send command:

Can somebody give me an Example of a Send command ?

like ppl are saying its diffrent to a !pay or !buy or !sell, buts its confusing me, please i need help i'am stuggling on this.
Quote from sun :Can somebody give me an Example of a Send command ?

Does anyone have a list of what Sun has been given, against what's in his InSim? I would be very interested in seeing that
#11 - Jakg
I have VERY little programming experience (BASIC ftw), and i've refrained from posting in these topics earlier to make sure I didn't look like an idiot but...

Can't you just query if the feild "cash" (or "$cash" or however you do it) for user "x" and if the value minus the value they send is greater then zero then remove £x from user "x" and add £x to the user they are sending it to.
Quote from Jakg :From here on in i'm using Pseudo-Code btw...

Can't you just query if the feild "cash" (or "$cash" or however you do it) for user "x" and if the value minus the value they send is greater then zero then remove £x from user "x" and add £x to the user they are sending it to.

That's not pseudocode
#13 - Jakg
How did I know I was gonna get pulled up on that...

I planned on writing it like that, but after not knowing if it would be "cash" or "$cash" i gave up.

NINJA EDIT!
Try something more like:


if (payment <= user[x].cash) {
remove value of payment from user[x].cash
add value of payment to user[y].cash
} else {
LAWL, NO MONIES. LAWL.
}

#15 - sun
ok.......
How far have you got so far?

What I'd suggest doing (without knowing how you're trying to do things at the moment) is firstly find out if the player who wants to send the money has enough to send. If they don't have enough to send then do nothing or print a message informing them they don't have enough. If they do have enough, find out the id of the player they want to send it to. Add to their money then remove from the player who sent it. Something you might want to think about is what would happen if there was an error in the middle of the transaction. If only one part of the transaction happens (i.e. if only the person who wants to send the money loses money or if only the person who is being sent money gets it) then you're in a bad state. You might want to put in some error handling that will compensate for that.

Something else you might want to think about is how you validate the send command. I noticed in another of your threads someone said your InSim crashed when a player tried to pay "2.2" credits. This would suggest to me (although I can't say for certain without seeing your code (no, I don't want to see your code )) that your code doesn't do proper validation of input. You might want to, for example, ensure the input is only a positive whole number. If you detect a negative amount of a number with decimal places then print a message and don't carry out the transaction. You could do that by, for example, checking for the presence of a full stop in the amount of money.
What I'd use is a try-catch, and cast to a UInt
Quote from dougie-lampkin :What I'd use is a try-catch, and cast to a UInt

Yeah, if I were writing it (in Java), I'd have a try/catch around it too.


try {
amount = Integer.parseInt(input);
} catch (NumberFormatException nfe) {
// input couldn't be parsed to an int (contained punctuation, non-numeric characters etc...)
amount = -1;
}

Then you could check if the return from that method was -1 and if it was you could print a message about invalid input. In this case it's safe to use -1 to signal an error because -1 isn't a valid input anyway, but if -1 was considered a valid input you could use an Integer object rather than the primitive int (checking for a non-null Integer in that case...).

Of course, that's specific to what language you're using and how it fits in with the rest of your programming style.
If you want to parse an int from a string in C#, it's better to use Int32.TryParse.


string input = "2";
int amount = 0;
if (Int32.TryParse(input, out amount))
// Amount was successfully parsed
else
// Amount couldn't be parsed.

What's the difference (if any) between Convert.ToInt32 and Int32.Parse?

I always use Convert, but that's just me
Ah, that explains it Thanks

Something I just thought of, which one is .ToString()?
Any performance benefit from using Convert vs Parse is academic, but using TryParse is better in my opinion, as it's neater and allows you to avoid exception handling. People overuse exception handling in C#, if you can avoid using try catch then you should. It's like if you are opening a file...


try
{
StreamReader sr = new StreamReader(path);
}
catch (FileNotFoundException)
{
Console.WriteLine("The file was not found.");
}

It's better to do this...

if(File.Exists(path))
StreamReader sr = new StreamReader(path);
else
Console.WriteLine("The file was not found.");

I guess that's a silly example, as you probably wouldn't open a file like that, but you get the idea.

I'm not sure what you mean about ToString(), but you can read up about it in the language reference. http://msdn2.microsoft.com/en- ... stem.object.tostring.aspx
I meant is it faster to Convert.ToString, String.Parse or .ToString()...

From what I've read now, it seems .ToString() is fastest
Theres no such thing as string.Parse() you just use ToString().
1
This thread is closed

!send command [Help Needed]
(31 posts, closed, started )
FGED GREDG RDFGDR GSFDG