Define String
#1

Quote:

C:\Users\Callum.Acer\Desktop\NCRP Working\gamemodes\LALSR.pwn(223) : error 017: undefined symbol "string"
C:\Users\Callum.Acer\Desktop\NCRP Working\gamemodes\LALSR.pwn(223) : error 017: undefined symbol "string"
C:\Users\Callum.Acer\Desktop\NCRP Working\gamemodes\LALSR.pwn(223) : error 029: invalid expression, assumed zero
C:\Users\Callum.Acer\Desktop\NCRP Working\gamemodes\LALSR.pwn(223) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.

I get this from the below:
Code:
	for(new x;x<sizeof(LSPDVehicles);x++)
	{
	    format(string, sizeof(string), "XMT %d", LSPDVehicles[x]);LINE 223
	    SetVehicleNumberPlate(LSPDVehicles[x], string);
	    SetVehicleToRespawn(LSPDVehicles[x]);
		Vehicle_Armor(LSPDVehicles[x]);
	}
Reply
#2

Code:
	for(new x;x<sizeof(LSPDVehicles);x++)
	{
            new string[128];
	    format(string, sizeof(string), "XMT %d", LSPDVehicles[x]);LINE 223
	    SetVehicleNumberPlate(LSPDVehicles[x], string);
	    SetVehicleToRespawn(LSPDVehicles[x]);
		Vehicle_Armor(LSPDVehicles[x]);
	}
Reply
#3

Quote:

C:\Users\Callum.Acer\Desktop\NCRP Working\gamemodes\LALSR.pwn(221) : error 017: undefined symbol "NEW"
C:\Users\Callum.Acer\Desktop\NCRP Working\gamemodes\LALSR.pwn(221) : error 017: undefined symbol "x"
C:\Users\Callum.Acer\Desktop\NCRP Working\gamemodes\LALSR.pwn(221) : warning 215: expression has no effect
C:\Users\Callum.Acer\Desktop\NCRP Working\gamemodes\LALSR.pwn(221) : error 001: expected token: ")", but found ";"
C:\Users\Callum.Acer\Desktop\NCRP Working\gamemodes\LALSR.pwn(221) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.

Code:
	for(NEW x;x<sizeof(LSPDVehicles);x++)[SIZE=6]LINE=221
	{
 		new string[128];
	    format(string, sizeof(string), "XMT %d", LSPDVehicles[x]);
	    SetVehicleNumberPlate(LSPDVehicles[x], string);
	    SetVehicleToRespawn(LSPDVehicles[x]);
		Vehicle_Armor(LSPDVehicles[x]);
	}
Reply
#4

Quote:
Originally Posted by MrCallum
View Post
Code:
	for(NEW x;x<sizeof(LSPDVehicles);x++)[SIZE=6]LINE=221
	{
 		new string[128];
	    format(string, sizeof(string), "XMT %d", LSPDVehicles[x]);
	    SetVehicleNumberPlate(LSPDVehicles[x], string);
	    SetVehicleToRespawn(LSPDVehicles[x]);
		Vehicle_Armor(LSPDVehicles[x]);
	}
Code:
	for(new x;x<sizeof(LSPDVehicles);x++)[SIZE=6]
		{
 			new string[128];
	    	format(string, sizeof(string), "XMT %d", LSPDVehicles[x]);
	    	SetVehicleNumberPlate(LSPDVehicles[x], string);
	    	SetVehicleToRespawn(LSPDVehicles[x]);
			Vehicle_Armor(LSPDVehicles[x]);
		}
		return 1;
	}
Reply
#5

Quote:
Originally Posted by virusa1
View Post
Code:
	for(new x;x<sizeof(LSPDVehicles);x++)[SIZE=6]
		{
 			new string[128];
	    	format(string, sizeof(string), "XMT %d", LSPDVehicles[x]);
	    	SetVehicleNumberPlate(LSPDVehicles[x], string);
	    	SetVehicleToRespawn(LSPDVehicles[x]);
			Vehicle_Armor(LSPDVehicles[x]);
		}
		return 1;
	}
2 important notices:

1. The string just is 4 characters + 1 integer. Why would you make it 128 bytes long? Even if the integer was at INTEGER_MAX, the string will never be longer than 14 chars. Add one for the closing string terminator for compatibility reasons, and youll end up with
new string[15];
as the smallest (and so optimal) string size. You can use even smaller values, but that depends on how big the LSPDVehicles numbers can be.

2. Always put variable definitions before the loop, not inside of it. Why would you create and destroy the same variable 1000 times, if its enough if you just define it once.

Small optimisations like this can make the difference between a well-running server and a laggy adventure.
Reply
#6

Quote:
Originally Posted by Mauzen
View Post
2 important notices:

1. The string just is 4 characters + 1 integer. Why would you make it 128 bytes long? Even if the integer was at INTEGER_MAX, the string will never be longer than 14 chars.

2. Always put variable definitions before the loop, not inside of it. Why would you create and destroy the same variable 1000 times, if its enough if you just define it once.
1. Well it was for example the 128 byte thing! I didn't knew how many bytes he needed!

2. Thanks i didn't knew that
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)