The online racing simulator
#1 - heawy
[C#]Connections List problem.[SOLVED]
Hey, i again stuck in some probably easy thing and need help.
I need Connection list with all who is on server, like this:


But like on screen, insim is copying only one player name, wont show all players and close buttons without player.
I think i do everything wrong but, maybe someone know how to fix it.

Part of code:
bool Found = false;
foreach (clsConnection i in Connections)
{
if (i.InGame == 1)
{
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 125, 3, 190, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 128, 3, 191, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 131, 3, 192, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 134, 3, 193, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 137, 3, 194, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 140, 3, 195, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 143, 3, 196, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 146, 3, 197, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 149, 3, 198, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 152, 3, 199, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 155, 3, 200, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 158, 3, 201, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 161, 3, 202, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 164, 3, 203, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, 167, 3, 204, i.UniqueID, 2, false);
}
}
else if (i.InGame == 0)
{
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 125, 3, 190, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 128, 3, 191, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 131, 3, 192, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 134, 3, 193, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 137, 3, 194, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 140, 3, 195, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 143, 3, 196, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 146, 3, 197, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 149, 3, 198, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 152, 3, 199, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 155, 3, 200, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 158, 3, 201, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 161, 3, 202, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 164, 3, 203, i.UniqueID, 2, false);
}
{
Found = true;
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, 167, 3, 204, i.UniqueID, 2, false);
}
}
}

You've unrolled the loop (but left the loop in) and created every button again for each player.

Please learn about logic and flow-control, it's fundamental to programming.
#3 - heawy
No idea what you mean
"i.PlayerName" everywhere is wrong yes?
You should try to understand what you've written and why it behaves the way it does. Follow the loops and conditions yourself, in your head. It's not magic, it's just logic.

You could do something like this, though of course I've not tested it:

int j = 0;
foreach (clsConnection i in Connections)
{
if (i.InGame == 1)
{
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, (byte)(125 + j * 3), 3, (byte)(190 + j), i.UniqueID, 2, false);
}
else if (i.InGame == 0)
{
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, (byte)(125 + j * 3), 3, (byte)(190 + j), i.UniqueID, 2, false);
}
j++;
}

But without understanding the code you're writing, and why, you're not going to get very far.
#5 - heawy
Really thanks now I understand that. I already made one insim for cruise just sometimes I stuck on stupid things like one number etc. Again thanks for help
#6 - heawy
No idea

#7 - kdo
Quote from PeterN :You should try to understand what you've written and why it behaves the way it does. Follow the loops and conditions yourself, in your head. It's not magic, it's just logic.

You could do something like this, though of course I've not tested it:

int j = 0;
foreach (clsConnection i in Connections)
{
if (i.InGame == 1)
{
InSim.Send_BTN_CreateButton(i.PlayerName + " ^2A", Flags.ButtonStyles.ISB_DARK, 4, 29, (byte)(125 + j * 3), 3, (byte)(190 + j), i.UniqueID, 2, false);
}
else if (i.InGame == 0)
{
InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, (byte)(125 + j * 3), 3, (byte)(190 + j), i.UniqueID, 2, false);
}
j++;
}

But without understanding the code you're writing, and why, you're not going to get very far.

Change the i.uniqueid to the player that need that panel

InSim.Send_BTN_CreateButton(i.PlayerName + " ^1•", Flags.ButtonStyles.ISB_DARK, 4, 29, (byte)(125 + j * 3), 3, (byte)(190 + j), i.UniqueID << HERE, 2, false);
#8 - heawy
As i said, i always miss things like this

It works! Thanks guys for help!

#9 - kdo
No probs dude. petern made the best code, just change few settings in the button option like the espace between each button cause 3 is a bit too little.

FGED GREDG RDFGDR GSFDG