The online racing simulator
If you really want to stick with the for loop, rather than opting for a foreach, which is easier to understand in the long run and I suspect probably better optimised (a .NET expert might want to confirm or deny), then the following:
for(int i = 0; i < MCI.NumC; i++)

Yup, you could do that, but (in my opinion ) the foreach makes it clearer as to what's happening, and the C# complier produces the same underlying (byte-)code anyway. As a rule of thumb in C#, unless I specifically want to know which iteration of a loop I'm on, I always use foreach.
NumC contains the number of valid compcars in the struct? So if you have 5 players on the track. only one compcar comes in. So wtf is i < MCI.NumC gonna do?
Quote from mcgas001 :NumC contains the number of valid compcars in the struct? So if you have 5 players on the track. only one compcar comes in. So wtf is i < MCI.NumC gonna do?

No. A CompCar is a single entry. The CompCar Info variable is defined as an array of up to 8 CompCar structs.

If NumC was always 1 then there would be absolutely no point in its existance.

If LFS_External is telling you that there is always 1, then that is a bug.

struct IS_MCI // Multi Car Info - if more than 8 in race then more than one of these is sent
{
byte Size; // 4 + NumC * 28
byte Type; // ISP_MCI
byte ReqI; // 0 unless this is a reply to an TINY_MCI request
byte NumC; // number of valid CompCar structs in this packet

[B]CompCar Info[8];[/B] // car info for each player, 1 to 8 of these (NumC)
};

There is usually more than one CompCar struct, unless there is only one person on the track. The CompCar is an array of up to 8 different CompCar structs, which are aligned one after the other in memory.
The NumC tells you how many CompCar's are in the MCI packet, regardless of how many players are on track.

If you want you could also use mci.Info.Length to get the number of elements in the CompCar array (presuming LFS_External doesn't use a fix sized array for it...).

Edit: I type too slow, TAA always beats me.
Grrrr, I hate being told crap from people. I wont say who told me about MCI but i sure wont listen to them again... :@
Quote from DarkTimes :Edit: I type too slow, TAA always beats me.

I do apologise I shouldn't really be posting in a thread on C# when I've barely used it anyway
Quote from the_angry_angel :I do apologise I shouldn't really be posting in a thread on C# when I've barely used it anyway

Seems you know more then me, So post away...
Quote from the_angry_angel :I do apologise I shouldn't really be posting in a thread on C# when I've barely used it anyway

No, that's cool. This discussion isn't really about C#, it's about the inner workings of InSim.

I think it's the Visual Studio IDE. Using intellisense so much means I'm only fast at typing the first two characters of every word... The rest take ages...
Quote from mcgas001 :Seems you know more then me, So post away...

More experience with InSim and the .NET languages are 2 entirely different things. When it comes to anything .NET-ish I'm sure you know more
Touché
-
(DarkTimes) DELETED by DarkTimes
This is the code in the example for earning cash:

for (int i = 0; i < Players.Count; i++)
{
decimal Speed = (decimal)((MCI.Info[i].Speed * (100f / 32768f)) * 3.6f);
decimal ConvSpeed = (decimal)(Speed * 25 / 1000);
Players[GetPlyIdx(MCI.Info[i].PLID)].Payout += ConvSpeed;
}

so, should it be < NumC instead? I'm confused here...
Yes, if you loop over the players then the program will crash (ArgumentOutOfRange exception) if there are more players than CompCars (which there will be if there are more than eight players). You need to loop over the CompCars in the MCI packet instead. I already posted previously in this thread a foreach loop that I think should work.
Thanks, just checking that you weren't on a completely different subject altogether
If people are hell-bent on using a for loop, then this should work...


for (int i = 0; i < mci.NumC; i++)
{
decimal speed = (decimal)((mci.Info[i].Speed * (100f / 32768)) * 3.6);
decimal convSpeed = (decimal)(speed * 25 / 1000);
Players[GetPlyIdx(mci.Info[i].PLID)].Payout += convSpeed;
}

I personally think the foreach is cleaner...
I agree foreach is cleaner, but you can't really use foreach here because the last mci packet has some invalid info[] objects since LFS External uses a static array for it.

Though you could use foreach and make a counter that breaks the loop when mci.numc is reached, but I don't think that is quite efficient.

Something like this:


void MCI(Packets.IS_MCI MCI)
{
byte counter;

foreach (Packets.CompCar info in MCI.Info)
{
// code

counter++;
if(counter >= MCI.NumC) break;
}
}

OK - I didn't know it uses a fixed sized array. In that case it would be better to use a for loop.
Quote from DarkTimes :OK - I didn't know it uses a fixed sized array. In that case it would be better to use a for loop.

Told you 'for' was better


T-RonX: Will this be fixed in the next version your working on?
Quote from DarkTimes :In this specific instance.

Yes, I would rather use foreach as like you say, its cleaner and much easier to use. I was going to say exactly what T-RonX said, only he beat me to it

Thats the reason for my persistance in the 'for' loop. I think i might try and carry on with my own lib. Although, Ill probley have the same issues...
Quote from mcgas001 :T-RonX: Will this be fixed in the next version your working on?

Not in the initial version of 1.1. It's not a big issue to deal with. I might change it to a dynamic array in future releases. Just use NumC for now.
i have got some buttons saying the location of yourself coming up but they only come up on the first person out of the pits, unless they spectate then join again, how could i get around this?
if two people left the pits the second person has the first persons MCI information like co-ordinates, could someone help me?

FGED GREDG RDFGDR GSFDG