Variable stocking
#1

Hello, i`ll get straight to my problem.
So, i`m trying to get a variable to stock my number of cars, which is easy.

Main bits of the code:
Код:
#define CAR_AMMOUNT (carscounted+1)
new carscounted;
OnGameModeInit()
//cars//
carscounted = CountVehicles();
The problem is that, the variable gets stocked after the CAR_AMMOUNT is defined (carscounted being token as a "0").
So, how would i be able to stock the variable before the CAR_AMMOUNT is defined so "carscounted" will be token as the actual number of cars ?
Reply
#2

I'm just saying out of ordinary, but the variable above the stock...idk
Reply
#3

That's what i thought of, sadly, you can't count the vehicles before on gamemodeinit, as they are situated there. It will just return you a "0".
Reply
#4

No one knows at all?
Reply
#5

Quote:
Originally Posted by KreeDz
Посмотреть сообщение
The problem is that, the variable gets stocked after the CAR_AMMOUNT is defined (carscounted being token as a "0").
So, how would i be able to stock the variable before the CAR_AMMOUNT is defined so "carscounted" will be token as the actual number of cars ?
This isn't the issue.

pawn Код:
#define macro variable+1
new variable = 1;

main()
{
    printf("%d", macro);
}
pawn Код:
if (strcmp("/output", cmdtext, true, 10) == 0)
{
    new string[32];
    carscounted = CountVehicles();
   
    format(string, sizeof(string), "%d", carscounted);
    SendClientMessage(playerid, -1, string);
   
    //printf("%d", carscounted);
    return true;
}
Reply
#6

Yeah, that would work perfectly for a command, the problem is that i`m using that macro throughout the script. So, it has to automatically count itself at ongamemodeinit. But as i said, it defines before counting taking it as a "zero".
Reply
#7

Quote:
Originally Posted by KreeDz
Посмотреть сообщение
Yeah, that would work perfectly for a command, the problem is that i`m using that macro throughout the script. So, it has to automatically count itself at ongamemodeinit. But as i said, it defines before counting taking it as a "zero".
The purpose of the command was to output the value of carscounted. If your having issues with the outputted value (it being 0), then what you have stated is correct, BUT your CountVehicles(); function is the cause.
Reply
#8

Actually, the output value is correct if i do printf("%d", carscounted); after the carscounted = CountVehicles();. And this is what makes me think that the value is defined incorrectly at the start of the script.
Код:
stock CountVehicles(){new cars;
for(new i = 0; i < 500; i++){
if(GetVehicleModel(i)!=0){
cars++;}}return cars;}
Reply
#9

Quote:
Originally Posted by KreeDz
Посмотреть сообщение
Actually, the output value is correct if i do printf("%d", carscounted); after the carscounted = CountVehicles();. And this is what makes me think that the value is defined incorrectly at the start of the script.
Код:
stock CountVehicles(){new cars;
for(new i = 0; i < 500; i++){
if(GetVehicleModel(i)!=0){
cars++;}}return cars;}
You must call this function AFTER the information relating to it. Use my example below as reference.

pawn Код:
#define macro CountVehicles()+1

stock CountVehicles()
{
    new cars;
    for(new i = 0; i < 500; i++) if(GetVehicleModel(i)!=0) cars++;
    return cars;
}

public OnGameModeInit()
{
    CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60);
    printf("%d",CountVehicles());
    printf("%d",macro);
    return 1;
}
Код:
Output:
1
2
Reply
#10

Alright, so, i have to move all the stuff that requires the macro after the ongamemodeinit. I`ll give it a try, it'll sure work as the macro return the right amount of cars after the cars are created. Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)