The online racing simulator
Cop Insim Mayhem
Hello,

For my insim when someone renames:
if (Connections[GetConnIdx(CPR.UCID)].PlayerName.StartsWith("^0[^1COP^0]"))
{
if (Connections[GetConnIdx(CPR.UCID)].Stat == 2)
{
InSim.Send_MTC_MessageToConnection("^2•^7 You are a On-Duty cop so FOLLOW THE RULES!", CPR.UCID, 0);
Connections[GetConnIdx(CPR.UCID)].IsOfficer = 1;
//ChaserUCID = Connections[GetConnIdx(CPR.UCID)].Username;
}
else
{
InSim.Send_MST_Message("/spec " + Connections[GetConnIdx(CPR.UCID)].Username);
InSim.Send_MTC_MessageToConnection("^1You are Not a Officer!", CPR.UCID, 0);
Connections[GetConnIdx(CPR.UCID)].IsOfficer = 0;
}
}
else
{
Connections[GetConnIdx(CPR.UCID)].IsOfficer = 0;
}

if (Connections[GetConnIdx(CPR.UCID)].PlayerName.StartsWith("^0[^2COP^0]"))
{
if (Connections[GetConnIdx(CPR.UCID)].Stat == 2)
{
InSim.Send_MTC_MessageToConnection("^2•^7 You are a On-Duty cop so FOLLOW THE RULES!", CPR.UCID, 0);
Connections[GetConnIdx(CPR.UCID)].IsCadet = 1;
}
else
{
InSim.Send_MST_Message("/spec " + Connections[GetConnIdx(CPR.UCID)].Username);
InSim.Send_MTC_MessageToConnection("^1You are Not a Cadet!", CPR.UCID, 0);
Connections[GetConnIdx(CPR.UCID)].IsCadet = 0;
}
}
else
{
Connections[GetConnIdx(CPR.UCID)].IsCadet = 0;
}

As a Cop This Popup Comes Up:

CODE FOR IT:
if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Chase == 1)
{
InSim.Send_BTN_CreateButton("^7Suspect: " + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Chase_Username, Flags.ButtonStyles.ISB_LIGHT, 5, 25, 7, 148, 22, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
//Condition
InSim.Send_BTN_CreateButton("^7Condition: " + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Chase_Condition, Flags.ButtonStyles.ISB_CLICK | Flags.ButtonStyles.ISB_LIGHT, 5, 25, 12, 148, 23, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
//Meters Away from Suspect
InSim.Send_BTN_CreateButton("^7Meters Away: " + Connections[GetConnIdx(Players[GetPlyIdx(ChaseeUCID)].UniqueID)].DistanceFromOfficer, Flags.ButtonStyles.ISB_LIGHT, 5, 25, 7, 173, 24, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
//Speed
InSim.Send_BTN_CreateButton("^7Suspects Speed: 0KMH", Flags.ButtonStyles.ISB_LIGHT, 5, 25, 12, 173, 25, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
}
else
{
//Suspect
InSim.Send_BTN_CreateButton("^7Suspect: None", Flags.ButtonStyles.ISB_LIGHT, 5, 25, 7, 148, 22, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
//Condition
InSim.Send_BTN_CreateButton("^7Condition: None", Flags.ButtonStyles.ISB_LIGHT, 5, 25, 12, 148, 23, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
//Meters Away from Suspect
InSim.Send_BTN_CreateButton("^7Meters Away: None", Flags.ButtonStyles.ISB_LIGHT, 5, 25, 7, 173, 24, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
//Condition
InSim.Send_BTN_CreateButton("^7Suspects Speed: None", Flags.ButtonStyles.ISB_LIGHT, 5, 25, 12, 173, 25, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
}

If you Ask the suspects speed,distance from officer don't really work.

ANYWAY

when I remove my cop tag and someone else puts a cop tag on I see the Start/End Chase Button but not the rest. The other player sees it all but not the start/stop chase button.
I have NO idea why it does that. Thanks

[DcS] stuntguy3000
if (Connections[GetConnIdx(CPR.UCID)].PlayerName.StartsWith("^0[^1COP^0]"))

that looks bad... i'd suggest using user name instead of racer name...
Quote from bunder9999 :
if (Connections[GetConnIdx(CPR.UCID)].PlayerName.StartsWith("^0[^1COP^0]"))

that looks bad... i'd suggest using user name instead of racer name...

So your saying that if you are a cop their is no tag or something?
Quote from stuntguy3000 :So your saying that if you are a cop their is no tag or something?

no, in fact, the opposite... your script checks for the presence of the cop tag, and acts accordingly... problem is, it doesn't check whether the person is actually a cop or not (i'm assuming they're chosen by the server admins)...

long story short, anyone who renames themselves could become a cop.

if that was your intention, my bad.
#5 - PoVo
Quote from bunder9999 :no, in fact, the opposite... your script checks for the presence of the cop tag, and acts accordingly... problem is, it doesn't check whether the person is actually a cop or not (i'm assuming they're chosen by the server admins)...

long story short, anyone who renames themselves could become a cop.

if that was your intention, my bad.

if (Connections[GetConnIdx(CPR.UCID)].Stat == 2)
{
}

This checks if the person is an Officer.
Quote from PoVo :
if (Connections[GetConnIdx(CPR.UCID)].Stat == 2)
{
}

This checks if the person is an Officer.

i see.

well, another thing i was thinking of...

if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Chase == 1)

what sets that to 1? it could also be possible that ".Stat" isn't being reset to 0 at some point.

i think you might need to show us more code.
-
(stuntguy3000) DELETED by stuntguy3000
-
(stuntguy3000) DELETED by stuntguy3000
Quote from bunder9999 :i see.

well, another thing i was thinking of...

if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Chase == 1)

what sets that to 1? it could also be possible that ".Stat" isn't being reset to 0 at some point.

i think you might need to show us more code.

if (Connections[GetConnIdx(CPR.UCID)].Stat == 2)
{
InSim.Send_MTC_MessageToConnection("^2•^7 You are a On-Duty cop so FOLLOW THE RULES!", CPR.UCID, 0);
Connections[GetConnIdx(CPR.UCID)].IsOfficer = 1;
//ChaserUCID = Connections[GetConnIdx(CPR.UCID)].Username;
}

thats in the code you both must of missed it lol
Quote from Dygear :Help != Programming for you.

Give a man a fish he eats for a day, teach a man to fish he eats for a life time.

Quote from filur :http://www.catb.org/esr/faqs/smart-questions.html#intro

Stuntguy3000, You are no longer asking for help. You are not learning from your mistakes. You have reached the point where you ask people to program for you, bit by bit, function by function, problem by problem.

Logic solves all your problems. Logic is common sense. Common sense is an essential part of yourself. If you are refusing to use common sense, then please stop making these "Please code this part of my insim for me" threads.

Now, please, return to your application, and think of how you could solve the problem. It is the best you can do for both - yourself, and the community. You are wasting people's time with these threads, as they(the people) do nothing more but code a part from what you claim to be "your" insim application.

Your problems are not exactly problems either. I see no errors. I see nothing that is different from your other request. They are all logical "problems". It is nothing that you don't know how to do. It's things that you refuse to even think of how to achieve.

I believe that your signature says something like this at the moment:
Quote :[DcS] Dutch Cruise Server
Insim Developer

http://dutchcruiseserver.freeforums.org/

Asking people to develop your insim application, and clicking the "create" button on freeforums.org does not make you a developer. Right now, you are not the DsC's developer. You are just the guy who gets people to code the insim for DsC.

So, please, read the article on the 2nd quote, and then come back if you have completed at least 20% of the steps.

I honestly hope that you would read all this and take notes for yourself, as in the way you are doing it right now - you are not learning almost anything.
Quote from broken :Stuntguy3000, You are no longer asking for help. You are not learning from your mistakes. You have reached the point where you ask people to program for you, bit by bit, function by function, problem by problem.

Logic solves all your problems. Logic is common sense. Common sense is an essential part of yourself. If you are refusing to use common sense, then please stop making these "Please code this part of my insim for me" threads.

Now, please, return to your application, and think of how you could solve the problem. It is the best you can do for both - yourself, and the community. You are wasting people's time with these threads, as they(the people) do nothing more but code a part from what you claim to be "your" insim application.

Your problems are not exactly problems either. I see no errors. I see nothing that is different from your other request. They are all logical "problems". It is nothing that you don't know how to do. It's things that you refuse to even think of how to achieve.

I believe that your signature says something like this at the moment:

Asking people to develop your insim application, and clicking the "create" button on freeforums.org does not make you a developer. Right now, you are not the DsC's developer. You are just the guy who gets people to code the insim for DsC.

So, please, read the article on the 2nd quote, and then come back if you have completed at least 20% of the steps.

I honestly hope that you would read all this and take notes for yourself, as in the way you are doing it right now - you are not learning almost anything.

You've said everything

Quote from PoVo :Yeah, that's very silly of you to ask for such a thing, when there is a cruise insim source with such a feature on LFSForums already

To Stuntguy3000: have you ever have a logic when it comes to a problem and look Live for Speed > Main > LFS Programmer Forum > Program / InSim requests > the thread is not filled with cruise question but you've ask too much which you are just asking other people to code to you but your aren't the coder/developer of your insim its the people who helps your insim not you.

I know its pretty useless to post here and say things what should be but its true coding is not simple but u have a logic to code it.

It's like your a master and commanding the insim to follow your mind. but I can't see that your commanding your slave(insim C#) but other people do it for you.

EDIT: It's up to you when you ask help and it's up to you to protect your INSIM bcuz hackers can be around somewhere here and seeing your code easily will break your insim. just advice to you.
#10 - PoVo
I wouldn't exactly call it hacking, it's more like 'bug using'.
Quote from PoVo :
if (Connections[GetConnIdx(CPR.UCID)].Stat == 2)
{
}

This checks if the person is an Officer.

You should really setup a constant for that value or a define that explains what 2 is.
Magic numbers man, they're the way of the future!

Actually.. reminds me of a funny story at work, I was developing something and instead of reinventing the wheel, I took our lead designers functioning code and modified it to fit with my task (it's cycling through real estate listings).. then I wondered why his worked, but mine produced weird results.. it wasn't until both of us sat down and looked, turned out he had only texted for a max of 1 listings displayed, so wrapping around wasn't a big deal, so he hardcoded in a value. and on further texting, his actually broke as well.

Strange how bugs like that can go missed for so long (there was a version of our CMS used for over a year with teh same bug)
Quote from Dygear :You should really setup a constant for that value or a define that explains what 2 is.

AFAIK those byte objects are from the Old Lc copy which povo release it

Stat 1 = cadet
Stat 2 = Officer
Stat 3 = Towtruck(if your a officer, removed stats goes to Towtruck)
Stat 4 = Member(allowed to be Officer but not towtruck)

Stat 10 = Remove cadet (unfinished)
Stat 11 = Remove Status of being Officer
Stat 12 = Remove as Towtruck
Stat 13 = Remove as Member

EDIT: I don't use this kind of idea because i feel bugged
For the stat types I would use an enum:

enum StatType
{
Cadet,
Officer,
TowTruck,
Member,
}

if (Connections[GetConnIdx(CPR.UCID)].Stat == StatType.Officer)
{
// Do something.
}

This makes the code easier to read and also safer, as you now get compile-time checking of the stat property.

While I'm at it this sort of code is incredibly inefficent:

if (Connections[[b]GetConnIdx(CPR.UCID)[/b]].Stat == 2)
{
InSim.Send_MTC_MessageToConnection("^2•^7 You are a On-Duty cop so FOLLOW THE RULES!", CPR.UCID, 0);
Connections[[b]GetConnIdx(CPR.UCID)[/b]].IsOfficer = 1;
}
else
{
InSim.Send_MST_Message("/spec " + Connections[[b]GetConnIdx(CPR.UCID)[/b]].Username);
InSim.Send_MTC_MessageToConnection("^1You are Not a Officer!", CPR.UCID, 0);
Connections[[b]GetConnIdx(CPR.UCID)[/b]].IsOfficer = 0;
}

GetConnIdx() iterates through the entire connection list each time you call it and in this short section of code it's being called four times! Instead you should do this:

[b]var conn = Connections[GetConnIdx(CPR.UCID)][/b];

if ([b]conn[/b].Stat == 2)
{
InSim.Send_MTC_MessageToConnection("^2•^7 You are a On-Duty cop so FOLLOW THE RULES!", CPR.UCID, 0);
[b]conn[/b].IsOfficer = [b]true[/b]; // Make IsOfficer a bool!!
}
else
{
InSim.Send_MST_Message("/spec " + [b]conn[/b].Username);
InSim.Send_MTC_MessageToConnection("^1You are Not a Officer!", CPR.UCID, 0);
[b]conn[/b].IsOfficer = false;
}

Not only is this much much faster it also makes the code easier to read. Of course a better solution is to make Connections a hash table, then you don't need to loop through the list at all.
Quote from DarkTimes :*The entire post*

I could not agree more with everything you just said.

While I rewrote this for PRISM & PHP, it's also general good practice for all languages.
Quote from DarkTimes :/text/

And you say that you suck? I learned a few things there. And found the answer to a question I've been asking myself a lot of times before.

The question was: Would it be more efficient if I made a reference(if that's the right term to use.. my terminology sucks) to the connection, or if I iterate through it every time. (yes, now that I think of it, it's pretty obvious, but back then I didn't have the knowledge I do now)

And I never fully understood enums either before, but now I just did, and with that. Again a pretty obvious thing, but I had learned things in the worst way possible back then, and learning everything new in this way was just horrible. Not any "specific" way, but just the way I was explaining things to myself.

(Offtopic ..and damn, when did I write all of this):
I can tell you, school stuffs up your head. I'm now working as a web dev from a few months, and being free from school freed up my brain like a lot. I ..like ..found a new way of thinking ..sounds stupid, but idk how to explain it, haha. And I only graduated a few months ago.
Morpha also helped me a lot too of course, by making me learn the basic and vital low level stuff. But now when I go back to those days - With the way I'm learning stuff now, it would be a lot easier for me to understand and remember those things, if I didn't know them already.

Maybe you could understand it if I gave you an example with history classes: Those were the hardest for me - remembering all these years and events and stuff that have had happened. Not only that, but the way it's written - it's so twisted and long, that when you reach the half of the sentence, you forget the beginning - literally I mean. Those books made me just memorize it all like it is. So when we had exams, I would go to that text in my mind and just write down what I remember from it.
I wasn't so smart back then either, so I couldn't just do like I would now - just process the vital information, connect it to the base, and find the logic for that to happen. The teachers gave us plans of course, but it didn't help with some of the books. Not all classes were like that of course, but this was just dis-motivational. And eventually, I gave up reading one day, and I thought it's because I was just being a super lazy teenager, which ..I was ..but some of the books were just written in a wrong way. You can't make a kid memorize all the vital stuff when you cover them up under twisted explanations, making them even longer too. If I was to learn everything we had to learn, I wouldn't have no time for myself, at all.
Quote from broken :The question was: Would it be more efficient if I made a reference(if that's the right term to use.. my terminology sucks) to the connection, or if I iterate through it every time. (yes, now that I think of it, it's pretty obvious, but back then I didn't have the knowledge I do now)

Yes you can refer to it as a reference, as it's a reference to an object on the heap. You are making a copy of the reference and storing it inside a variable.

It is a common mistake many programmers make to perform expensive operations multiple times. It is however dependent on your domain knowledge, that is, your knowledge of what is happening beneath the covers in a language. Take these two programs that both take a string and print out each character on a separate line.

string str = "Hello, world!";

for (int i = 0; i < str.Length; i++)
{
Console.WriteLine(str[i]);
}

int i;
char str[] = "Hello, world!";

for (i = 0; i < strlen(str); i++)
{
printf("%c\n", str[i]);
}

The first program is C# and the second is C. Both of these programs look similar and both have fundamentally the same code, except that the C# version will run many times faster than the C version (yes even through C is C and supposed to be SUPER FAST OMG!)

The reason for this is how they each handle strings internally. In both languages string are just arrays of chars, but what differs is how each language determines the length of the string. In C strings are NULL terminated, meaning that the last character of each string is NULL (or '\0'). In the example above that fact is hidden from you, as the compiler is smart enough to add that NULL character automatically.

The actual array of chars that the compiler initialises looks like this, with a NULL char appended on the end:

char str[] = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!', [b]'\0'[/b] };

So how does strlen figure out the length of a string?

int strlen(char* str)
{
int i = 0;
while (str[++i]);
return i;
}

It loops through the str counting each character until it finds a NULL (which is the same as false in C) and then returns the count. So each time the for loop in the example calls strlen is has to loop through the entire string to find the NULL. What if the string was thousands of characters long? That would take a long time.

C# however is a different beast. The .NET framework doesn't use NULL terminating characters to deliminate strings, instead it uses a system known as PASCAL strings, or length-prefixed strings. What that means is that each string in .NET is prefixed with a hidden int that contains the the length of the string that follows it. You can imagine it like this:

HEAD | TAIL
1101 | 'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!'

This is a gross simplification as .NET actually uses 16-bit wide unicode strings to store text and the header is way more complicated, but anyway... So how does the .NET framework get the string length? Simple, it just returns the header. So as you can see, two pieces of code which appear to do the same thing, actually have massively different consequences depending on how the underlying function calls are implemented.

The basic point is that there is no "right-way" to do these kinds of things, it depends on the language, the framework and the implementation. The only way you can decide whether its OK to call a function or a property in a loop or multiple times is by having as much domain knowledge of the underlying architecture as possible.

(Note: In the .NET Framework library as rule of thumb properties such as length are almost always pretty efficient and expensive operations are normally wrapped in function calls).
Quote from DarkTimes :
string str = "Hello, world!";

for (int i = 0; i < str.Length; i++)
{
Console.WriteLine(str[i]);
}

int i;
char str[] = "Hello, world!";

for (i = 0; i < strlen(str); i++)
{
printf("%c\n", str[i]);
}


So, would that make it almost as fast? :
int i;
char str[] = "Hello, world!";
int ilimit = strlen(str);

for (i = 0; i < ilimit; i++)
{
printf("%c\n", str[i]);
}

That way the for loop won't be calling the strlen func every time.
And C becomes SUPER FAST OMG! again. Or - almost as fast as C# (I never even thought that I'd say this).

I really had no idea how these stuff work behind the scenes. You can't imagine how much you've expanded my knowledge.

And, yay, my terminology was not completely wrong!
Quote from broken :That way the for loop won't be calling the strlen func every time.

Yes! It's as simple as saving a result that you know your going to use more then once. strlen is not a very expensive function in C, but calling multiple times needlessly compounds a bad situation and makes it worse. It went from having to iterate over the length of the string once, to having to iterate over the length string multiple times and your doing it over the length of the string. There for it has the problem of taking longer for greater input sizes, in an exponential fashion! I'm sure DarkTime's can convert that into Big O notation for you, but I can't as I get a little fuzzy with that stuff. I'm pretty sure it's n(log (n)), that means that it takes longer the greater the input sizes.
Wouldn't it be O(n²)? I'm not good with Big O either.
Quote from DarkTimes :Wouldn't it be O(n²)? I'm not good with Big O either.

Yeah, I guess it would be as it maps over its-self by the number of its-self = It squares its-self. So, yeah, that's bad. Of course now that broken fixed it, it now just is O(n), and that's much faster when you get to larger strings.

So to explain this in plain English, what we where just talking about is the number of operations (O) that the computer must go through to get the result, where n is a number (length, in our case) given for the variable length input.

So we take our string 'Hello, world!' and find it's length, witch is 13 characters for this example. We have our n now, it's 13. Now we can find the number of operations for each case the CPU will have to do in order for it to be completed.

In the case where we don't save the value of strlen and compute it over and over again we have O(n²) and that equates too O(13²), or O(169). That's 169 operations to get our final result.

In the second case where we save our strlen and thus only get it once so nothing happens to n, O(n) is our equation and that means, O(13). As n does not need to be multiplied in any way, as we are not running the function many times, we again have our answer. 13 is our final result when it comes to number of operations.

So in the one had we have 13 operations to get a result, in the other we have 169. Just think of this runs 1000 times a second on your computer, a simple small oversight just became quite costly in terms of CPU power. What if we take a larger input like for example the number of clients we have on the LFS forum right now, 272. We have our base of n value of 272 and in our second example we have our answer already, but for our first flawed function we have to square it so that's 73,984.
Actually, the fixed one would do n*2 . Because, once - it iterates through the string to get it's length, and then another time to display it. So that's 26 operations. Still, multiplying it 2 times, is heaps better than squaring it(if that's the right term).

In this case, I believe that it becomes just as fast as C#. Or maybe even a bit faster, or maybe a bit slower. But it's almost the same - Now C saves 2 values, just as C# does. C does this in 2 operations, while C# should do something similar?

Also, if this is how C determines the length of the string ..
int strlen(char* str)
{
int i = 0;
while (str[++i]);
return i;
}

.. wouldn't DarkTimes' example be even more efficient by copying and modifying it to suit our needs? What I mean:
char str[] = "Hello, world!";

int i = 0;
while (str[++i])
{
printf("%c\n", str[i]);
}

Now, that would be 13 operations straight.
I'm feeling proud of myself ..haha
Quote from broken :Actually, the fixed one would do n*2 . Because, once - it iterates through the string to get it's length, and then another time to display it. So that's 26 operations. Still, multiplying it 2 times, is heaps better than squaring it(if that's the right term).

I was only referring the the number of operations it takes to get the string length, not the whole function.

Quote from broken :In this case, I believe that it becomes just as fast as C#. Or maybe even a bit faster, or maybe a bit slower. But it's almost the same - Now C saves 2 values, just as C# does. C does this in 2 operations, while C# should do something similar?

I think that in this case, it would be slightly faster then C# because we also have to consider the intrinsic operations that happen that our out of our control in C#. Consider that the header does have to be calculated, although that happens automatically, it is still a calculation that the CPU must do.

Quote from broken :Also, if this is how C determines the length of the string ..
int strlen(char* str)
{
int i = 0;
while (str[++i]);
return i;
}

.. wouldn't DarkTimes' example be even more efficient by copying and modifying it to suit our needs? What I mean:
char str[] = "Hello, world!";

int i = 0;
while (str[++i])
{
printf("%c\n", str[i]);
}

Now, that would be 13 operations straight.
I'm feeling proud of myself ..haha

Yes, but I worry for code readability at this point. Without knowing that NULL is also equal to FALSE, this could becomes quite ambiguous even slightly encrypted to a new programmer. I would add a comment letting them know what is going on. By all means tho, program flat out so that you can make the program as fast as you can, but comment where the your solution is non obvious without knowing the fundamentals of the system.

Also consider that you should ...
Quote from Coding Horror :Always, always write for simplicity and readability first. That should be your main goal when writing code: to express yourself as simply and clearly as you possibly can. If you must optimize, use real optimizations based on actual metrics in a functional application. Not hypothetical theory based on some article you read on some website.



Bringing up the good point, if you MUST optimize then you should optimize. Your time is worth more then CPU time, if the time you spent optimizing the code is greater then the time you reap from it then don't bother optimizing. So, at this point, how slow is slow? Some things to keep in mind are response time limits, but should those not apply then there is really no point in optimizing the code. You should also check to make sure that what you have done is in fact optimizing. Or you may find you self asking the question, Why aren't my optimizations optimizing?

One last foot note from Donald Knuth's Computer Programming as an Art, P. 671 says "Premature optimization is the root of all evil in programming."
-
(DarkTimes) DELETED by DarkTimes
#24 - PoVo
Quote from DarkTimes :GetConnIdx() iterates through the entire connection list each time you call it and in this short section of code it's being called four times! Instead you should do this:

[b]var conn = Connections[GetConnIdx(CPR.UCID)][/b];

if ([b]conn[/b].Stat == 2)
{
InSim.Send_MTC_MessageToConnection("^2•^7 You are a On-Duty cop so FOLLOW THE RULES!", CPR.UCID, 0);
[b]conn[/b].IsOfficer = [b]true[/b]; // Make IsOfficer a bool!!
}
else
{
InSim.Send_MST_Message("/spec " + [b]conn[/b].Username);
InSim.Send_MTC_MessageToConnection("^1You are Not a Officer!", CPR.UCID, 0);
[b]conn[/b].IsOfficer = false;
}


Personally I've been using this type of thing, for a long time :

Quote :clsConnection Conn = Connections[GetConnIdx(CPR.UCID)];

Quote from Dygear :[optimization talk]

But, in our case, with a few comments, telling the programmer what this code does, it is perfect imo. I mean, this is not one of those cases where you go like "Imma do this and this, and then add more code to optimize it all and it should be so much more optimized". It's one of the cases in which you save code. True, you make readability a bit worse, but C becomes 2 times faster than C# in the current case. I'm quite a big fan of less and faster code (as long as I know what it does of course ..and that's what comments are for).

I know that sometimes taking too much time on optimization can just have the opposite impact on your creation, but my simplistic brain tells me that this is quite not the case. And, yes - not 'not quite the case', but indeed 'quite not the case'.
1

FGED GREDG RDFGDR GSFDG