HELP!! Scariest bug ever -
Incubator - 15.10.2011
HELP!!
I can't even explain it, here is my code:
Код:
#define LICENSE_PLATE_LENGTH 7
stock GeneratePlate(vehicleid)
{
new licenseplate[LICENSE_PLATE_LENGTH],
numberstr[5], len;
format(numberstr, 5, "%d", vehicleid);
len = strlen(numberstr);
for(new c; c < LICENSE_PLATE_LENGTH; c++)
{
if(c > 1 && c <= 1 + len)
{
licenseplate[c] = numberstr[c - 2];
}
else switch©
{
case 0, 1: licenseplate[c] = random('Z' - 'A') + 'A';
default: licenseplate[c] = random('9' - '0') + '0';
}
}
print(licenseplate);
return licenseplate;
}
Then, try it out by:
Код:
public OnGameModeInit()
{
for(new i; i < 100; i++) GeneratePlate(i);
Spent so much time trying to solve this... just can't.
Re: HELP!! Scariest bug ever -
GrimR - 15.10.2011
You go from if to else switch.....
thats not right lol
Re: HELP!! Scariest bug ever -
Incubator - 15.10.2011
That is completely legitimate.
Re: HELP!! Scariest bug ever -
GrimR - 15.10.2011
There is no such thing as:
Else switch
Only:
Else {
switch () {
}
}
Yet i only see one set of brackets and that is a multi line statement.....
Re: HELP!! Scariest bug ever -
Incubator - 15.10.2011
Try it out yourself, the syntax is definitely okay.
Just like you'd do
Код:
if(statement) var++;
instead of
Код:
if(statement)
{
var++;
}
Re: HELP!! Scariest bug ever -
GrimR - 15.10.2011
Yeah that's for a single line statement only, a lot of languages do that.
A multi line statement is usually stricter with requirement for parenthesis.
The compiler might be allowing it, but I would be concerned as to whether it really works as intended lol.
pawn Код:
if(c > 1 && c <= 1 + len)
{
licenseplate[c] = numberstr[c - 2];
}
else switch(c)
{
case 0, 1: licenseplate[c] = random('Z' - 'A') + 'A';
default: licenseplate[c] = random('9' - '0') + '0';
}
Your if has only one line statement but has parenthesis, your else has a switch and 2 statements but no parenthesis..... It could be valid but it looks like a bad habit to get into.
I'll take a look.
Re: HELP!! Scariest bug ever -
Incubator - 15.10.2011
Quote:
Originally Posted by GrimR
Yeah that's for a single line statement only, a lot of languages do that.
A multi line statement is usually stricter with requirement for parenthesis.
The compiler might be allowing it, but I would be concerned as to whether it really works as intended lol.
pawn Код:
if(c > 1 && c <= 1 + len) { licenseplate[c] = numberstr[c - 2]; } else switch(c) { case 0, 1: licenseplate[c] = random('Z' - 'A') + 'A'; default: licenseplate[c] = random('9' - '0') + '0'; }
Your if has only one line statement but has parenthesis, your else has a switch and 2 statements but no parenthesis..... It could be valid but it looks like a bad habit to get into.
I'll take a look.
|
Alright, I'll do it that way from now on, thanks.
Now please lets go back to my matter.
Re: HELP!! Scariest bug ever -
GrimR - 15.10.2011
Yeah I see, I assume you mean the wacked out characters?
My first thought is..... random() on the SA:MP wiki has no mention of using it in the way that you are lol.
What kind of license plate are you trying to generate (is it just 6 random number/char), it sort of looks like 2 chars and 4/5 numbers AB12345?
I already made on working at the moment that generates 7 the same as above format without any issues.
Re: HELP!! Scariest bug ever -
GrimR - 15.10.2011
Here, this will generate the 7 random num/chars:
pawn Код:
new abc[][26] =
{
{"A"}, {"B"}, {"C"}, {"D"}, {"E"}, {"F"}, {"G"}, {"H"}, {"I"}, {"J"}, {"K"},
{"L"}, {"M"}, {"N"}, {"O"}, {"P"}, {"Q"}, {"R"}, {"S"}, {"T"}, {"U"}, {"V"},
{"W"}, {"X"}, {"Y"}, {"Z"}
};
new rNum[][10] =
{
{"0"}, {"1"}, {"2"}, {"3"}, {"4"}, {"5"}, {"6"}, {"7"}, {"8"}, {"9"}
};
#define LICENSE_PLATE_LENGTH 7
stock GeneratePlate(vehicleid)
{
new licenseplate[LICENSE_PLATE_LENGTH];
for (new c; c < LICENSE_PLATE_LENGTH; c++)
{
new rand = random(sizeof(abc));
new rand2 = random(sizeof(rNum));
switch (c)
{
case 0, 1: licenseplate[c] = abc[rand][0];
default : licenseplate[c] = rNum[rand2][0];
}
}
return licenseplate;
}
And in OnGameModeInit for testing:
pawn Код:
for (new i; i < 100; i++) { print(GeneratePlate(i)); }
Obviously to change length you modify your #DEFINE, and to mix up chars and numbers, modify the case statement accordingly.
Re: HELP!! Scariest bug ever -
Incubator - 15.10.2011
Yeah, the wacked out characters, also the freaky beeping the computer does when launching the server.
I guess I'll pick your way then, thanks.
btw this:
Код:
new abc[][26] =
{
{"A"}, {"B"}, {"C"}, {"D"}, {"E"}, {"F"}, {"G"}, {"H"}, {"I"}, {"J"}, {"K"},
{"L"}, {"M"}, {"N"}, {"O"}, {"P"}, {"Q"}, {"R"}, {"S"}, {"T"}, {"U"}, {"V"},
{"W"}, {"X"}, {"Y"}, {"Z"}
};
is better to be replaced with
Код:
new abc[26] =
{
'A', 'B', ....
};