vehicle system
#1

I am scripting a vehicle system according to this tutorial: https://sampforum.blast.hk/showthread.php?tid=416104
And I get this error over and over, help please.

PHP код:
forward public LoadVehicleData(vehicleIDname[], value[]);
public 
LoadVehicleData(vehicleIDname[], value[])
{
    new 
location[32];
    
INI_Int("Model"VehicleInfo[vehicleID][vModel]);
    for(new 
04i++) format(locationsizeof(location), "Loc%d"i), INI_Float(locationVehicleInfo[vehicleID][vLoc][i]);
    
INI_Int("Color 1"VehicleInfo[vehicleID][vColor1]);
    
INI_Int("Color 2"VehicleInfo[vehicleID][vColor2]);
    
INI_String("Owner"VehicleInfo[vehicleID][vOwner], MAX_PLAYER_NAME);
    
VehicleInfo[vehicleID][vLocked] = INI_Int("Locked") == true false;
    return 
1;
}
stock VehicleSave(vehicleID)
{
    new 
INI:dFile INI_Open(VehiclePath(vehicleID))
    new 
location[32];
    
INI_WriteInt(dFile"Model"VehicleInfo[vehicleID][vModel]);
    for(new 
04i++) format(loactionsizeof location"Location: %i"i), INI_Float(locationVehicleInfo[vehicleID][vLoc][i]);
    
INI_WriteInt(dFile"Color 1"VehicleInfo[vehicleID][vColor1]);
    
INI_WriteInt(dFile"Color 2"VehicleInfo[vehicleID][vColor2]);
    
INI_WriteInt(dFile"Owner"VehicleInfo[vehicleID][vOwner]);
    
INI_WriteInt(dFile"Locked"VehicleInfo[vehicleID][vLocked] ? 0);
    
INI_Close(dFile);
    return 
1;

Quote:

The error line of both stocks:
PHP код:
for(new 04i++) format(loactionsizeof location"Location: %i"i), INI_Float(locationVehicleInfo[vehicleID][vLoc][i]); 
error 029: invalid expression, assumed zero
error 001: expected token: ";", but found error 017: undefined symbol "i"
fatal error 107: too many error messages on one line

Reply
#2

Код:
for(new i = 0; i < 4; i++) format(loaction, sizeof location, "Location: %i", i), INI_Float(location, VehicleInfo[vehicleID][vLoc][i]);
sizeof(location) ? you forgot () and location not loaction
Reply
#3

Replace the comma before INI_Float by a semicolon. And since the for-loop has more than two different instructions in its body, I recommend putting them each on a separate line surrounded by function brackets:

PHP код:
    for(new 04i++) {
        
format(loactionsizeof location"Location: %i"i);
        
INI_Float(locationVehicleInfo[vehicleID][vLoc][i]);
    }
    
INI_WriteInt(dFile"Color 1"VehicleInfo[vehicleID][vColor1]);
    
INI_WriteInt(dFile"Color 2"VehicleInfo[vehicleID][vColor2]);
    
INI_WriteInt(dFile"Owner"VehicleInfo[vehicleID][vOwner]);
    
INI_WriteInt(dFile"Locked"VehicleInfo[vehicleID][vLocked] ? 0); 
FYI: spaces in your line name are going to give you a lot of trouble and you don't need a loop. Plus, shouldn't it be INI_WriteFloat?:
PHP код:
    INI_WriteFloat(dFile"LocationX"VehicleInfo[vehicleid][vLoc][0]);
    
INI_WriteFloat(dFile"LocationY"VehicleInfo[vehicleid][vLoc][1]);
    
INI_WriteFloat(dFile"LocationZ"VehicleInfo[vehicleid][vLoc][2]);
    
INI_WriteFloat(dFile"LocationA"VehicleInfo[vehicleid][vLoc][3]);
    
INI_WriteInt(dFile"Color1"VehicleInfo[vehicleID][vColor1]);
    
INI_WriteInt(dFile"Color2"VehicleInfo[vehicleID][vColor2]);
    
INI_WriteInt(dFile"Owner"VehicleInfo[vehicleID][vOwner]);
    
INI_WriteInt(dFile"Locked"VehicleInfo[vehicleID][vLocked] ? 0); 
And you don't need an array for the location either:
PHP код:
Float:vLocX,
Float:vLocY,
Float:vLocZ,
Float:vLocA
PHP код:
    INI_WriteFloat(dFile"LocationX"VehicleInfo[vehicleid][vLocX]);
    
INI_WriteFloat(dFile"LocationY"VehicleInfo[vehicleid][vLocY]);
    
INI_WriteFloat(dFile"LocationZ"VehicleInfo[vehicleid][vLocZ]);
    
INI_WriteFloat(dFile"LocationA"VehicleInfo[vehicleid][vLocA]);
    
INI_WriteInt(dFile"Color1"VehicleInfo[vehicleID][vColor1]);
    
INI_WriteInt(dFile"Color2"VehicleInfo[vehicleID][vColor2]);
    
INI_WriteInt(dFile"Owner"VehicleInfo[vehicleID][vOwner]);
    
INI_WriteInt(dFile"Locked"VehicleInfo[vehicleID][vLocked] ? 0); 
EDIT: and I forgot to even mention the loading of your data. Same applies. You don't need the loop, put each instruction on a separate line (exception is when the loop only has one instruction).

You're saving the location on 'Location : %i', which is wrong by itself, but you then load from 'Loc%i'.
Reply
#4

vLoc[4]; has 4 variables in 1.
plus, Honestly, I don't understand INI as I just updated to it 2days ago.
I'll try it
Reply
#5

The use of arrays where normal variable are sufficient can have an influence on efficiency and performance of your script: https://sampforum.blast.hk/showthread.php?tid=580289 , plus using arrays for coordinates reduces readability - IMO.

EDIT: I just quickly reviewed the code again and saw your use of 'forward public'. You're doing it wrong, though.
PHP код:
forward public somefunction();
somefunction() {} 
Slice's post about it: http://forum.sa-mp.com/showpost.php?...3&postcount=30
Reply
#6

Woooooooooooooww arrays are much heavier than non-arrays variables. Thank you for the first link, I definetely learned the difference now.

Current code:
PHP код:
forward public LoadVehicleData(vehicleIDname[], value[]);
public 
LoadVehicleData(vehicleIDname[], value[])
{
    new 
location[32];
    
INI_Int("Model"VehicleInfo[vehicleID][vModel]);
    for(new 
04i++)
    {
        
format(locationsizeof location"Location: %i"i);
        
INI_Float(locationVehicleInfo[vehicleID][vLoc][i]);
    }
    
INI_WriteFloat(dFile"LocationX"VehicleInfo[vehicleID][vLoc][0]);
    
INI_WriteFloat(dFile"LocationY"VehicleInfo[vehicleID][vLoc][1]);
    
INI_WriteFloat(dFile"LocationZ"VehicleInfo[vehicleID][vLoc][2]);
    
INI_Int("Color 1"VehicleInfo[vehicleID][vColor1]);
    
INI_Int("Color 2"VehicleInfo[vehicleID][vColor2]);
    
INI_String("Owner"VehicleInfo[vehicleID][vOwner], MAX_PLAYER_NAME);
    
VehicleInfo[vehicleID][vLocked] = INI_Int("Locked") == true false;
    return 
1;
}

stock VehicleSave(vehicleID)
{
    new 
INI:dFile INI_Open(VehiclePath(vehicleID))
    new 
location[32];
    
INI_WriteInt(dFile"Model"VehicleInfo[vehicleID][vModel]);
    for(new 
04i++)
    {
         
format(locationsizeof location"Location: %i"i);
        
INI_Float(locationVehicleInfo[vehicleID][vLoc][i]);
    }
    
INI_WriteFloat(dFile"LocationX"VehicleInfo[vehicleID][vLoc][0]);
    
INI_WriteFloat(dFile"LocationY"VehicleInfo[vehicleID][vLoc][1]);
    
INI_WriteFloat(dFile"LocationZ"VehicleInfo[vehicleID][vLoc][2]);
    
INI_WriteInt(dFile"Color 1"VehicleInfo[vehicleID][vColor1]);
    
INI_WriteInt(dFile"Color 2"VehicleInfo[vehicleID][vColor2]);
    
INI_WriteInt(dFile"Owner"VehicleInfo[vehicleID][vOwner]);
    
INI_WriteInt(dFile"Locked"VehicleInfo[vehicleID][vLocked] ? 0);
    
INI_Close(dFile);
    return 
1;

Reply
#7

It has been a while since the last time I worked with y_ini so my knowledge is a bit rusty.

- You can't put spaces in your line names. So: "Color 1" should become "Color1". (source: https://sampforum.blast.hk/showthread.php?tid=597411)
- I don't see the point of that for-loop.
- Don't use INI_Write... When you're loading data.
- This is the correct syntax for forwarding your public function like that (source: http://forum.sa-mp.com/showpost.php?...3&postcount=30):
PHP код:
forward public SomeFunction();
SomeFunction() { } 
- Are you not going to save the vehicle's angle?

- This seems very redundant to me:
PHP код:
VehicleInfo[vehicleID][vLocked] = INI_Int("Locked") == true false
Just load it like all the other values:
PHP код:
INI_Int("Locked"VehicleInfo[vehicleID][vLocked]); 
Reply
#8

Ooh ok, I think the best solution would be to read a ini tutorial, thanks btw.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)