10.06.2012, 08:14
Ugh how much I hate that question. Here's my answer: I won't fix it for you. If I don't manage to make you understand your error in this long reply, you will come back to this forum the moment you have an error again and eventually you never actually learned anything, which is not the point.
So, let me explain to you in detail what your code does and I am sure you will see the obvious mistake right away:
Let's take a closer look shall we?
You created an array called aBenzin that has MAX_PLAYERS amount of drawers. Each drawer can hold a number. Now the importance here is that the playerid is the key to each drawer. In order for you to open a drawer you must use the correct key. Let's take a look at the error line again:
You're using the vehicleid as key here, but is it the correct key? Let's look once more at the declaration:
Wait a moment? Do you see what I see? It says players. So how can I use a vehicle key in order to access a drawer which requires a player key? The drawer didn't open and your Boss(the compiler) moaned at you for failing.
Now let's go have a look in the actual code again and find the correct key shall we?
Aha, we're looping through every player, which means we basically go through every drawer, from the top to the buttom with their respected key playerid. So, in order to open the proper drawer we must use the playerid key!
Awesome! The drawer opened! I am proud of you, but there is still one problem. Fuel is a bunch of documents all with a number written on them. Though there is only space enough for one single document in the drawer? How do we know which document to put into the drawer? Wait a second! Let's have a look at that declaration shall we?
Okay! Do you see what I see? Yes! It uses the vehicle key! Now where did we find the vehicle key? Oh right! We actually check it here:
The player is sitting in that vehicle and obviously has the key! So let's use that key to find the correct document that holds the fuel of that vehicle and put it into the drawer!
Wow! This is amazing! So we find the document that shows the fuel of the vehicle and put it into the drawer of the appropriate player bar! It works!!
Hope you get it now =).
Final Edit:
"Don't ask how to do things but ask why, because running against a wall because one said so is not smart."
I think it is very important for people to understand their code, so I hope I've managed to do a little of that for you this time and hopefully you will have learned enough to be able to investigate your error by yourself next time. =)
Regards.
So, let me explain to you in detail what your code does and I am sure you will see the obvious mistake right away:
pawn Код:
public AracBenzin()
{
// Here you begin to loop through all players I guess you understand that the code below repeats each time.
for(new playerid; playerid < MAX_PLAYERS; playerid++)
{
new vehicleid;
// here you fetch the vehicleid the player is in and make sure that the progress bar has been created for that player
if((vehicleid = GetPlayerVehicleID(playerid)) && aBenzin[playerid] != INVALID_BAR_ID)
{
// Here you change the progress bar of the >VEHICLEID< to an ARRAY without index. This line is the actual error!
SetProgressBarValue(aBenzin[vehicleid], Fuel);
UpdateProgressBar(aBenzin[playerid], playerid);
}
}
}
pawn Код:
new Bar:aBenzin[MAX_PLAYERS];
pawn Код:
SetProgressBarValue(aBenzin[vehicleid], Fuel);
pawn Код:
new Bar:aBenzin[MAX_PLAYERS];
Now let's go have a look in the actual code again and find the correct key shall we?
pawn Код:
// Here you begin to loop through all players I guess you understand that the code below repeats each time.
for(new playerid; playerid < MAX_PLAYERS; playerid++)
pawn Код:
SetProgressBarValue(aBenzin[playerid], Fuel);
pawn Код:
new Fuel[MAX_VEHICLES] = {100,...};
pawn Код:
if((vehicleid = GetPlayerVehicleID(playerid)) && aBenzin[playerid] != INVALID_BAR_ID)
pawn Код:
SetProgressBarValue(aBenzin[playerid], Fuel[vehicleid]);
Hope you get it now =).
Final Edit:
"Don't ask how to do things but ask why, because running against a wall because one said so is not smart."
I think it is very important for people to understand their code, so I hope I've managed to do a little of that for you this time and hopefully you will have learned enough to be able to investigate your error by yourself next time. =)
Regards.