Randomised string not displaying
#1

I'm assigning random flightnumbers to aircraft, however, when I try to format the string into a message nothing gets displayed..

Код:
	if(IsAircraft(vehicleid))
	{
		new
			sHold[MAX_FLIGHT_NR+1];
		sHold[0]= RandomLetter();
		sHold[1]= RandomLetter();
	
		for(new i=2; i<MAX_FLIGHT_NR; i++)
		{
			sHold[i]= RandomNumber();
		}
		strpack(vInfo[vehicleid][FlightNR], sHold);
	}
Код:
stock RandomLetter()
{
	new
		Letters[27]= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return Letters[random(26)];
}

stock RandomNumber()
{
	new
		Numbers[11]= "0123456789";
	return Numbers[random(10)];
}
Blank:
Код:
format(sHold, sizeof sHold, "[Radio] #%s: %s", vInfo[iID][FlightNR], params);
Reply
#2

Shouldn't you set
pawn Код:
vInfo[iID][FlightNR] to RandomNumber()
Reply
#3

No since RandomNumber(); Only returns one number at a time.
Reply
#4

So you're setting it to:
pawn Код:
for(new i=0;i<sizeof(vInfo[iID][FlightNR]);i++)
{
    new RandomFlight = random(2);
    switch(RandomFlight)
    {
        case 0:
        {
            format(vInfo[iID][FlightNR], sizeof(vInfo[iID][FlightNR]), "%s%s",vInfo[iID][FlightNR],RandomLetter());
        }
        case 1:
        {
            format(vInfo[iID][FlightNR], sizeof(vInfo[iID][FlightNR]), "%s%i",vInfo[iID][FlightNR],RandomNumber());
        }
    }
}
Also note that random(x) returns a MAXIMUM of x-1.
Reply
#5

I think you' re missing the point of what I'm trying to do, the flightID assigned is 8 characters (MAX_FLIGHT_NR)

The first 2/8 characters are randomised letters, the other 6 are random numbers.

EDIT:
Your post did give me a solution though. I was overcomplicating things and I' ve simplified it a bit now. Thanks!
Reply
#6

Update:

format(vInfo[iID][FlightNR], sizeof(vInfo[iID][FlightNR]), "%s%s",vInfo[iID][FlightNR],RandomLetter());

Results in invalid expression
Reply
#7

Quote:
Originally Posted by Intoxicated
Посмотреть сообщение
Update:

format(vInfo[iID][FlightNR], sizeof(vInfo[iID][FlightNR]), "%s%s",vInfo[iID][FlightNR],RandomLetter());

Results in invalid expression
sizeof is iffy on array elements, try setting it to MAX_FLIGHT_NR.
Reply
#8

Still doesn't work, can someone please find me a way to return a randomised letter and a randomised number?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)