Quote:
Originally Posted by ISmokezU
Guessing.
PHP код:
aDG_Max_Warn[10] = {1, 2, ..........};
Prints : 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ?
So what if i want it to print to 100, 100 dots?
TIL
https://en.wikipedia.org/wiki/Modulo_operation
|
Funny how you could think about that. Imagine a vector of size 1000+ .
It was a pretty unexpected question and a smart observation for his example. I guess that this made me smile more than it should.
---------------------------------------
Quote:
Originally Posted by Hansrutger
Код:
some3dtext = CreateDynamic3DTextLabel("hi", -1, 0.0, 0.0, 0.0, 0.0, 0);
DestroyDynamic3DTextLabel(some3dtext);
printf("%i", some3dtext); //prints 1
if (IsValidDynamic3DTextLabel(some3dtext ))
{
printf("first is valid..."); //this doesn't print
}
some3dtext = INVALID_3DTEXT_ID;
printf("%i", some3dtext); //prints 65535
if (IsValidDynamic3DTextLabel(some3dtext))
{
printf("invalid is valid..."); //this doesn't print
}
So I learned that I don't have to reset them by equalizing them with INVALID_3DTEXT_ID since both methods make them invalid. Silly perhaps but had to be sure so wanted to test. :P
|
No ! That's very bad ! IDs aren't unique in a server session, the same ID can be used infinite times. The only IDs unique in a server session are timers (I hope I didn't miss other elements). They start at 1 and don't have any limit.
If you won't reset the variable, something like this could happen:
PHP код:
new Text3D:vartext;
public OnGameModeInit( )
{
vartext = Create3DTextLabel( ... ); // textlabel ID 0
Create3DTextLabel( ... ); // textlabel ID 1
Create3DTextLabel( ... ); // textlabel ID 2
}
public OnPlayerPickUpPickup( playerid, pickupid )
{
if( IsValid3DTextLabel( vartext ) ) // let's say you want it to be deleted when any pickup is picked up
Delete3DTextLabel( vartext ); // textlabel ID 0 is now deleted, so it isn't valid
}
// later
Create3DTextLabel( ... ); // because textlabel ID 0 is no longer valid, and it is the first free ID, this 3DText will be created with ID 0.
// you probably don't want it to be deleted when any player pick any pickup, but it will be deleted, because ID 0, which is
// stored in "vartext" is now valid (so IsValid3DTextLabel will return 1 for textlabel ID 0)
I recommend you to reset to -1 every element(timer [even if IDs are unique]/vehicles/objects/etc)-storing variable after deletion. You won't need to call functions like IsValid3DTextLabel (functions are slower than variables) anymore, only "variable != -1" . Or, yet better, instead of -1 use the correct definitions: INVALID_VEHICLE_ID, INVALID_ACTOR_ID, INVALID_OBJECT_ID, etc. . If there's no "invalid" definition you could just use -1, to be sure, as all of them are starting at 0 or 1 (
https://sampwiki.blast.hk/wiki/Starting_IDs ).
I actually had problems some years ago because I didn't reset variables after destroying. Random elements were deleted when they shouldn't (they can even change properties, for example you could add components to the wrong vehicle, or setting bad objects positions and so on. Every function that can apply to an element ID). Reset variables ! Otherwise it will give you headaches in the future.