[Help] Delete3DTextLabel
#1

When i'm in duty, the text label show, but when i put the command again, to back to the player mode, the Text Label dont delete, someone know why?

PHP код:
ACMD:admin[1](playeridparams[])
{
    if(
GetPlayerAdminLevel(playerid) < 2)
        return 
Msg(playeridRED"[ > ] Vocк nгo tem permissгo para usar este comando.");
    new 
name[MAX_PLAYER_NAME];
    new 
Text3D:label Create3DTextLabel("Admin"0x33CCFFFF30.040.050.010.00);
    
GetPlayerName(playeridnamesizeof(name));
    if(
GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
    {
        
Msg(playeridRED"[ > ] Vocк nгo pode fazer isso enquanto estб espiando!");
        return 
1;
    }
    if(!
IsPlayerOnAdminDuty(playerid))
    {
        
TogglePlayerAdminDuty(playeridtrue);
        
MsgAdminsF(1NovoA"[ > ] O(a) Administrador(a){FFFFFF} %s {00c0ff}saiu do modo jogador!"name);
        
Attach3DTextLabelToPlayer(labelplayerid0.00.00.2);
    }
    else
    {
        
TogglePlayerAdminDuty(playeridfalse);
        
MsgAdminsF(1NovoA"[ > ] O(a) Administrador(a){FFFFFF} %s {00c0ff}entrou no modo jogador!"name);
           
Delete3DTextLabel(label);
    }
    return 
1;

Reply
#2

Someone?
Reply
#3

1) You're creating a label and trying to store it with a local variable.

2) Your label duplicates everytime you use the command.
Reply
#4

So, you can help-me to fix it? and leave the code the right way?
Reply
#5

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
Understanding scope is important here. When you create a variable in a function, that variable only exists until the function exits or "returns" (hence, the `return` keyword).

In this case, you have a command - which is just a function - which allocates a new local variable `label`. This variable holds the numeric identifier for the text label created by `Create3DTextLabel`. These numeric identifiers are unique to each label, hence "identifier" or "ID". The problem you're facing is, that numeric identifier is lost when the function ends. Then when you call the function (via command) again, it starts from scratch and allocates a whole new variable and creates a whole new label.

What you need to do is store the numeric identifier that identifies the label associated with the player globally. You also need to map (or "associate") label IDs to player IDs using an array. That array may have one element for each player and each element stores a label's ID. You can then use the player's ID as the index into the array.
I wanted to thank you, and was very grateful that you explained the situation to me, and not simply gave the code, for me to "copy and paste", I believe that copying and pasting is not learning, much less develops the logical intellect to program, thank you for explaining, I was able to make the code work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)