Help With "new"
#1

I have noticed people do this a lot in their scripting...
pawn Код:
new LSPDJail = CreateDynamicObject(971, 266.30337524414, 92.817451477051, 1002.5568237305, 0.000000, 0.000000, 270.27026367188,-1,-1,-1,200); //
Instead of doing this:
pawn Код:
new LSPDJail; (TOP OF SCRIPT)

LSPDJail = CreateDynamicObject(971, 266.30337524414, 92.817451477051, 1002.5568237305, 0.000000, 0.000000, 270.27026367188,-1,-1,-1,200); (UNDER OnGameModeInit())
Every time I add
pawn Код:
new
to the beginning of the script line, I get errors such as:
Код:
C:\CnR SA-MP Server\gamemodes\CnR.pwn(31) : warning 204: symbol is assigned a value that is never used: "LSPDJail"
C:\CnR SA-MP Server\gamemodes\CnR.pwn(115) : error 017: undefined symbol "LSPDJail"
C:\CnR SA-MP Server\gamemodes\CnR.pwn(120) : error 017: undefined symbol "LSPDJail"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Why?
Reply
#2

It refers to the scope of the variable. A variable created at the top of the script, is global and can be used anywhere. A variable created inside of a function, callback, etc. can only be used within the same structure it was created in. People will create variables inside of functions instead of making them global because the variable is only needed inside that specific function, callback, etc. I hope that makes sense.
Reply
#3

Quote:
Originally Posted by Backwardsman97
It refers to the scope of the variable. A variable created at the top of the script, is global and can be used anywhere. A variable created inside of a function, callback, etc. can only be used within the same structure it was created in. People will create variables inside of functions instead of making them global because the variable is only needed inside that specific function, callback, etc. I hope that makes sense.
Yes, that does make a lot of sense... Thank you very much...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)