The online racing simulator
#1 - sun
Problems in C# [Only post if you know whats wrong]
hi,
---------------------------------------------------------------------
Please dont abuse me in this post like i do stuff what i DO NOT DO. |
|
----------------------------------------------------------------------

I have problems with the bank code. i've fixed most of them but i get these errors.. (at the bottom the picture)





If you look closely, you can see that the, 'Officer on' and 'BankRobbable' BankChaseInProgress' dont exist. I've tryed defining them, but i dont get any luck at all... but above the errors, theres a robberUCID like i said in my other post what arnt definable.

Timerlength is also underlined to.. What does that mean ? and why has it unerlined the Car Names inside the quotion marks ?

If you can help then great please post!

Regards

Owen.
lol........ they are not even defined.....

have you tried defining them as false first, like this?


bool Officer = false;

And why is bankchaseinprogress an INT value when it could be a boolean?
Can i just ask

isn't that dougie-lampkin's that he posted on lfs forum?

edit: i guess OfficerOn would check if there are any officers on the server if there are then make it true if the check comes back with no officers on the server then make it false.. its probably saying it doesn't exist because it doesn't know what "OfficerOn" means.
#4 - sun
Right the Bool did the job of the officer on: bool Officer = false; but now do i have to keep putting bools in for the others ?
i have just tried the same insim that u are using now and it works fine so why are u editing it all?
#6 - sun
i'am taking bits out of robs to try out in another insim base... iam testing the officer system in another base.
#7 - sun
this is the full code... i'll post my clients.cs to.

if (((MCI.Info[0].X / 196608) >= -190) && ((MCI.Info[0].X / 196608) <= -189) && ((MCI.Info[0].Y / 196608) >= -251) && ((MCI.Info[0].Y / 196608) <= -249) && ((MCI.Info[0].Speed / 147) <= 3) && (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].IsOfficerORCadet == 0))
{
bool OfficerOn = false;
if (OfficerOn == true)
{
bool BankRobbable = false;
if ((BankRobbable == true) && (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].AddedBankTime == 0) && (BankTimerCoolDown == 0))
{
if (BankChaseInProgress == 0)
{
for (byte b = 0; b < Players.Count; b++)
{
if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[b].PLID)].UniqueID)].IsOfficerORCadet == 1)
{
if (BankChaseInProgress == 0)
{
switch (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].CurrentCar)
{
case "UF1":
TimerLength = 5;
break;
case "XFG":
TimerLength = 5;
break;
case "XRG":
TimerLength = 6;
break;
case "LX4":
TimerLength = 6;
break;
case "RAC":
TimerLength = 7;
break;
case "FXO":
TimerLength = 7;
break;
case "RB4":
TimerLength = 9;
break;
case "LX6":
TimerLength = 7;
break;
case "XRT":
TimerLength = 9;
break;
case "FZ5":
TimerLength = 9;
break;
case "UFR":
TimerLength = 10;
break;
case "XFR":
TimerLength = 10;
break;
case "FXR":
case "XRR":
case "FZR":
TimerLength = 12;
break;
case "MRT":
TimerLength = 7;
break;
case "FOX":
case "FBM":
case "FO8":
TimerLength = 12;
break;
case "BF1":
TimerLength = 15;
break;
}

BankCash =
new Random().Next(2000, 7500);
InSim.Send_MST_Message(
"/msg ^6|^7 " + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].PlayerName + "^7 (" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].Username + ") robbed the bank");
InSim.Send_MST_Message(
"/msg ^6|^7 and stole ^1€" + BankCash + "^7!");
InSim.Send_MST_Message(
"/msg ^6|^7 Car: " + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].CurrentCar + " - Chase Timer: " + TimerLength);
BankChaseInProgress = 1;
RobberUCID = Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].UniqueID;
BankTimer.Enabled =
true;
}
}
foreach (clsConnection C in Connections)
{
if (C.IsOfficerORCadet == 1)
InSim.Send_MTC_MessageToConnection(
"^1The Bank Has Been Robbed!", C.UniqueID, 0);
}
}
}
else if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].UniqueID != RobberUCID && Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].IsOfficerORCadet == 0 && Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].IsInZone == 0)
{
InSim.Send_MTC_MessageToConnection(
"^1You cannot rob the bank while a robbery is in progress", Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].UniqueID, 0);
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].IsInZone = 1;
}
}
else if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].IsInZone == 0)
{
InSim.Send_MST_Message(
"/msg ^6|^7 " + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].PlayerName + "^7 (" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].Username + ") tried to rob the bank");
InSim.Send_MST_Message(
"/msg ^6|^7 but was spotted by security.");
InSim.Send_MTC_MessageToConnection(
"^1You have been spotted by the bank", Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].UniqueID, 0);
InSim.Send_MTC_MessageToConnection(
"^1Please try again later", Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].UniqueID, 0);
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].AddedBankTime += 600;
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].IsInZone = 1;
}
}
else if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].IsInZone == 0)
{
InSim.Send_MTC_MessageToConnection(
"^1You can only rob the bank when an officer is on-duty", Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].UniqueID, 0);
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].IsInZone = 1;
}
}
else
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].IsInZone = 0;
}
#8 - sun
This is the Client.cs... but its in txt because i couldnt post it in .cs
Try declaring bool OfficerOn, etc. at the very top of your function, outside any if, else or foreach statements.
#10 - sun
thats what i've done.. the underlined bit is the bool what is outside the 'if'

bool OfficerOn = false;
if (OfficerOn == true)
{
bool BankRobbable = false;
if ((BankRobbable == true) && (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[0].PLID)].UniqueID)].AddedBankTime == 0) && (BankTimerCoolDown == 0))

No, you didn't.
Define them all in one cluster**** at the beginning of your function... I don't know C#, but it has to have your "bool OfficerOn = true; bool BankRobbable = false;" etcera at the top of the function (Just following the opening "{" for that section of code).

In all fairness, I still can't believe you're asking for simple shit like this after a year of "programming".
#13 - sun
like:
bool
OfficerOn = false;
{

bool
BankRobbable = false;
{

bool
bankwahtever= false;
{
Not at all. Post the whole section of code.
#15 - sun
i did it.. now all whats moaning is these:

case "UF1":
TimerLength = 5;
break;
case "XFG":
TimerLength = 5;
break;
case "XRG":
TimerLength = 6;
break;
case "LX4":
TimerLength = 6;
break;
case "RAC":
TimerLength = 7;
break;
case "FXO":
TimerLength = 7;
break;
case "RB4":
TimerLength = 9;
break;
case "LX6":
TimerLength = 7;
break;
case "XRT":
TimerLength = 9;
break;
case "FZ5":
TimerLength = 9;
break;
case "UFR":
TimerLength = 10;
break;
case "XFR":
TimerLength = 10;
break;
case "FXR":
case "XRR":
case "FZR":
TimerLength = 12;
break;
case "MRT":
TimerLength = 7;
break;
case "FOX":
case "FBM":
case "FO8":
TimerLength = 12;
break;
case "BF1":
TimerLength = 15;
break;
As far as I know, switch statements can only handle integers, you're asking it to work with strings.
I do believe that C# can handle switch statements on strings, I personally don't recommend it (since it would be slow) and never used it myself. Saying that the syntax may or may not be wrong, which Sun could use the MSDN to check the correct syntax, as it will tell him better than I can right now. (type switch put the cursor on it, and hit F1)
.. I checked, and it does work with strings...
i read your comments and you are doing quite an effort... but...

TOO DEEP NESTING!! AAAAAH!
#20 - sun
read your comments and you are doing quite an effort... but...

TOO DEEP NESTING!! AAAAAH!

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


WTH was all that ?
why dont you make your own officer system? maybe a little bit easier for you since your starting it from scratch and have less chance of missing stuff out
Quote from Robbo01 :why dont you make your own officer system? maybe a little bit easier for you since your starting it from scratch and have less chance of missing stuff out

No. No. No. No. No. A whole world of trouble there.

On topic (I promise to behave...). Sun, you might want to take a look at what's called the scope or visibility of methods/variables. The scope of a variable basically defines what can see it to be able to use it. When the compiler says it can't find/recognise a variable (and you're sure it has been declared!) the problem may be that it isn't within the scope of the code that's trying to find it. In the following code, I've defined the int variable called "count" inside an If statement. When I try to reference it outside the If statement I can't, because it's not in the scope of that code (that code outside the loop can't see it).


if(true) {
int count = 0;
}

count++;

If I want to be able to reference the count variable outside the loop, I have to declare it outside the loop, so it's in scope:


int count;

if(true) {
count = 0;
}

count++;

If you have a piece of code which is broken into many functions/methods then you need to think about the scope of variables across those methods. Variables declared inside methods will NOT be available in other methods (unless you pass them as parameters). The simple solution (which is necessary in some cases but sloppy/lazy in others) is to declare the variables globally (i.e. "at the top of the file"). This way the variables will be available to all of the functions within the class at all times. In the following example, the variable called "globalCount" is a global variable (available all the time to all methods) and the variable "localCount" is a local variable to the "increaseCounts" method.


private int globalCount = 0;

public void increaseCounts() {
int localCount = 0;

localCount++;
globalCount++;
}

Understanding the scope of variables/functions is a fundamental aspect to programming. I was harsh on you the other day and a lot of other people have been too. The reason for that harshness is that you just don't seem to be putting the effort in to learn. Please, please, please go away and take a look at the scope of variables. It will help you out MASSIVELY if you want to continue programming!
Lolz I wrote this yonks ago. Real spaghetti code. If I wanted to, several thousand lines could be removed. But I gave up

@Sun: You can't just cut and paste parts of it into other programs, unless you actually know and understand what each part does. Otherwise, this happens...
Quote from amp88 :No. No. No. No. No. A whole world of trouble there.


just wanted to see him try
#25 - sun
:banghead: damit. so, is there a way to get the case's to work ? defining wont work in Client.cs... is there somthing else to ? i'am just sooo confuse

:biggun:
1

FGED GREDG RDFGDR GSFDG