[PROBLEM COMPILING] - Filterscript
#1

Hi, i have this code:

Код:
#include <a_samp>

  new Normal_Cars[]= {401,402,404,405,410,412,413,418,419,421,
	422,426,436,439,445,458,466,467,474,475,478,479,480,489,491,492,496,507,
	516,517,518,526,527,529,533,534,536,542,543,546,547,549,550,551,554,558,
	561,566,575,576,580,585,600}; // Normal Cars

  new Bicycles[] = {509,481,510};

  new NRandom = random(sizeof(Normal_Cars)); // Random Normal Cars
  new BRandom = random(sizeof(Bicycles)); // Random bicycles


public OnFilterScriptInit()
{


  AddStaticVehicle(NRandom,1836.7377,-1854.2983,13.1691,358.8890,0,1); // cheapcar1
  AddStaticVehicle(NRandom,1841.1429,-1870.9862,13.1690,180.3903,0,1); // cheapcar2
  AddStaticVehicle(NRandom,1791.4736,-1888.7665,13.1774,178.7570,0,1); // normalcar1
  AddStaticVehicle(NRandom,1778.0460,-1913.4692,13.1675,275.8655,0,1); // normalcar2
  AddStaticVehicle(NRandom,1802.2800,-1915.4110,13.1742,273.1066,0,1); // normalcar3
  AddStaticVehicle(418,1922.2260,-1860.6227,13.3405,168.1871,0,1); // somevan
  AddStaticVehicle(BRandom,1881.0487,-1887.8309,13.2597,89.8009,0,1); // bikecycle1
  AddStaticVehicle(NRandom,1826.8505,-1797.0966,13.2413,0.7763,0,1); // norcar4
  AddStaticVehicle(NRandom,1816.2935,-1796.4451,13.2409,181.2451,0,1); // norcar6
  AddStaticVehicle(587,1717.8387,-1737.7451,13.2408,270.3658,0,1); // sportcar
  AddStaticVehicle(459,1782.3186,-1701.4119,13.2818,6.8769,0,1); // workcar
  AddStaticVehicle(498,1765.7163,-1692.0504,13.2076,92.0528,0,1); // vanwork
  AddStaticVehicle(NRandom,1742.8043,-1693.8945,13.3243,178.1735,0,1); // normalcar
  
	return 1;
}

public OnFilterScriptExit()
{

	return 1;
}
Why it fails to compile? (Pawn compiles it but an error appears like if the program has to close).

If I put everything inside OnFilterScriptInit(), it compiles well, but in game I can't see the cars.
Reply
#2

You will probably find that this
pawn Код:
new Bicycles[] = {509,481,510};
is the problem.
Reply
#3

Make the variables for the randoms outside the brackets. ie

pawn Код:
new Random; // GOOD

OneCallback()
{
  new Random; // BAD
}
Reply
#4

Don't Understand both of ya.

1 - Why Bicycles is wrong?

2 - I think I've created the variables and arrays outside the callbacks.

I've found that the problem is this two lines:

Код:
new NRandom = random(sizeof(Normal_Cars)); // Random Normal Cars
  new BRandom = random(sizeof(Bicycles)); // Random bicycles
If I compile them in the Global area, it fails; inside OnFilterScriptInit() it compiles good (still I can't see the cars that it should generate from taking a random number from an array).

I've found a working way, but every car is the same:

Код:
#include <a_samp>

new Normal_Cars[]= {401,402,404,405,410,412,413,418,419,421,
	422,426,436,439,445,458,466,467,474,475,478,479,480,489,491,492,496,507,
	516,517,518,526,527,529,533,534,536,542,543,546,547,549,550,551,554,558,
	561,566,575,576,580,585,600}; // Normal Cars
	
new Bicycles[] = {509,481,510};




public OnFilterScriptInit()
{

  new NRandom = random(sizeof(Normal_Cars)); // Random Normal Cars
  new BRandom = random(sizeof(Bicycles)); // Random bicycles

  AddStaticVehicle(Normal_Cars[NRandom],1836.7377,-1854.2983,13.1691,358.8890,0,1); // cheapcar1
  AddStaticVehicle(Normal_Cars[NRandom],1841.1429,-1870.9862,13.1690,180.3903,0,1); // cheapcar2
  AddStaticVehicle(Normal_Cars[NRandom],1791.4736,-1888.7665,13.1774,178.7570,0,1); // normalcar1
  AddStaticVehicle(Normal_Cars[NRandom],1778.0460,-1913.4692,13.1675,275.8655,0,1); // normalcar2
  AddStaticVehicle(Normal_Cars[NRandom],1802.2800,-1915.4110,13.1742,273.1066,0,1); // normalcar3
  AddStaticVehicle(418,1922.2260,-1860.6227,13.3405,168.1871,0,1); // somevan
  AddStaticVehicle(Bicycles[BRandom],1881.0487,-1887.8309,13.2597,89.8009,0,1); // bikecycle1
  AddStaticVehicle(Normal_Cars[NRandom],1826.8505,-1797.0966,13.2413,0.7763,0,1); // norcar4
  AddStaticVehicle(Normal_Cars[NRandom],1816.2935,-1796.4451,13.2409,181.2451,0,1); // norcar6
  AddStaticVehicle(587,1717.8387,-1737.7451,13.2408,270.3658,0,1); // sportcar
  AddStaticVehicle(459,1782.3186,-1701.4119,13.2818,6.8769,0,1); // workcar
  AddStaticVehicle(498,1765.7163,-1692.0504,13.2076,92.0528,0,1); // vanwork
  AddStaticVehicle(Normal_Cars[NRandom],1742.8043,-1693.8945,13.3243,178.1735,0,1); // normalcar
  
	return 1;
}

public OnFilterScriptExit()
{

	return 1;
}
I still don't know why it fails to compile when I use the Randoms Outside the Callbacks.
Reply
#5

this
pawn Код:
new Bicycles[] = {509,481,510};
is like this
pawn Код:
new Bicycles[] {

{509},
{401},
{510}
}
Reply
#6

Quote:
Originally Posted by BiG_Sm0k3
this
pawn Код:
new Bicycles[] = {509,481,510};
is like this
pawn Код:
new Bicycles[] {

{509},
{401},
{510}
}
Actually, I think is the same...

Ask around.
Reply
#7

Quote:
Originally Posted by clavador
Quote:
Originally Posted by BiG_Sm0k3
this
pawn Код:
new Bicycles[] = {509,481,510};
is like this
pawn Код:
new Bicycles[] {

{509},
{401},
{510}
}
Actually, I think is the same...

Ask around.
Try it dude, it may work, I had the same problem and that fixed it.
Reply
#8

Quote:
Originally Posted by clavador
I've found a working way, but every car is the same:
You need to get random number for every vehicle, not only once:
pawn Код:
new size = sizeof(Normal_Cars);

    AddStaticVehicle(Normal_Cars[random(size)], .....);
    AddStaticVehicle(Normal_Cars[random(size)], .....);
    AddStaticVehicle(Normal_Cars[random(size)], .....);
    AddStaticVehicle(Normal_Cars[random(size)], .....);
    ......
Quote:
Originally Posted by clavador
I still don't know why it fails to compile when I use the Randoms Outside the Callbacks.
Quote:
Originally Posted by pawn-lang.pdf
A global declaration appears outside a function and a global variable
is accessible to any function. Global data objects can only be
initialized with constant expressions.
==> you cannot initialize global variables using any functions or other variables.
Reply
#9

Quote:
Originally Posted by ZeeX
Quote:
Originally Posted by clavador
I've found a working way, but every car is the same:
You need to get random number for every vehicle, not only once:
pawn Код:
new size = sizeof(Normal_Cars);

    AddStaticVehicle(Normal_Cars[random(size)], .....);
    AddStaticVehicle(Normal_Cars[random(size)], .....);
    AddStaticVehicle(Normal_Cars[random(size)], .....);
    AddStaticVehicle(Normal_Cars[random(size)], .....);
    ......
Quote:
Originally Posted by clavador
I still don't know why it fails to compile when I use the Randoms Outside the Callbacks.
Quote:
Originally Posted by pawn-lang.pdf
A global declaration appears outside a function and a global variable
is accessible to any function. Global data objects can only be
initialized with constant expressions.
==> you cannot initialize global variables using any functions or other variables.
Thanks!!!!

I forgot that the variables should be a fixed value when initialized as global.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)