Updating 3D text label makes it dissapear
#1

Basically I want to add a sort of a "loading bar" with 3D text labels for when player gets revived, but it doesn't seem to work. It starts at two bars and just disappears, that's it.

pawn Code:
RevivingText[playerid] = Create3DTextLabel("(( |--------- ))\nHELPING UP", COLOR_DARKGREEN, pX, pY, pZ, 25.0, -1, 0);

        reviveCount[playerid] = 0;
        reviveTextTimer[playerid] = SetTimerEx("updateRevivingText", 500, true, "ddfff", playerid, reviveCount[playerid], pX, pY, pZ);

forward updateRevivingText(playerid, count, Float:x, Float:y, Float:z);
public updateRevivingText(playerid, count, Float:x, Float:y, Float:z)
{
    switch(count)
    {
        case 0: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||-------- ))\nHELPING UP");
        case 1: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||------- ))\nHELPING UP");
        case 2: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||------ ))\nHELPING UP");
        case 3: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||----- ))\nHELPING UP");
        case 4: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||---- ))\nHELPING UP");
        case 5: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||--- ))\nHELPING UP");    
        case 6: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||||-- ))\nHELPING UP");
        case 7: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||- ))\nHELPING UP");
        case 8: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||| ))\nHELPING UP");
        case 9:
        {
            Delete3DTextLabel(RevivingText[playerid]);
            KillTimer(reviveTextTimer[playerid]);
            reviveCount[playerid] = 0;
            count = 0;
            return 1;
        }
    }
    count++;
    reviveCount[playerid]++;
    return 1;
}
Reply
#2

`count` is always 0, it does not matter if you modify its value in the callback. The initial value you passed in `SetTimerEx` is used.

pawn Code:
reviveCount[playerid] = 0;
reviveTextTimer[playerid] = SetTimerEx("updateRevivingText", 500, true, "d", playerid);
// position is not used in `Update3DTextLabelText` function and counter will be increased and checked in the callback
pawn Code:
forward updateRevivingText(playerid);
public updateRevivingText(playerid)
{
    switch (reviveCount[playerid]++) // ++ or -- after the variable returns the old value and then it increases/decreases
    {
        case 0: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||-------- ))\nHELPING UP");
        case 1: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||------- ))\nHELPING UP");
        case 2: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||------ ))\nHELPING UP");
        case 3: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||----- ))\nHELPING UP");
        case 4: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||---- ))\nHELPING UP");
        case 5: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||--- ))\nHELPING UP");    
        case 6: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||||-- ))\nHELPING UP");
        case 7: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||- ))\nHELPING UP");
        case 8: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||| ))\nHELPING UP");
        case 9:
        {
            Delete3DTextLabel(RevivingText[playerid]);
            RevivingText[playerid] = Text3D: INVALID_3DTEXT_ID;

            KillTimer(reviveTextTimer[playerid]);
            reviveTextTimer[playerid] = -1; // always reset ids to avoid destroying/killing the wrong thing

            reviveCount[playerid] = 0;
        }
    }
}
Reply
#3

Quote:
Originally Posted by Calisthenics
View Post
`count` is always 0, it does not matter if you modify its value in the callback. The initial value you passed in `SetTimerEx` is used.

pawn Code:
reviveCount[playerid] = 0;
reviveTextTimer[playerid] = SetTimerEx("updateRevivingText", 500, true, "d", playerid);
// position is not used in `Update3DTextLabelText` function and counter will be increased and checked in the callback
pawn Code:
forward updateRevivingText(playerid);
public updateRevivingText(playerid)
{
    switch (reviveCount[playerid]++) // ++ or -- after the variable returns the old value and then it increases/decreases
    {
        case 0: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||-------- ))\nHELPING UP");
        case 1: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||------- ))\nHELPING UP");
        case 2: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||------ ))\nHELPING UP");
        case 3: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||----- ))\nHELPING UP");
        case 4: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||---- ))\nHELPING UP");
        case 5: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||--- ))\nHELPING UP");    
        case 6: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||||-- ))\nHELPING UP");
        case 7: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||- ))\nHELPING UP");
        case 8: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||| ))\nHELPING UP");
        case 9:
        {
            Delete3DTextLabel(RevivingText[playerid]);
            RevivingText[playerid] = Text3D: INVALID_3DTEXT_ID;

            KillTimer(reviveTextTimer[playerid]);
            reviveTextTimer[playerid] = -1; // always reset ids to avoid destroying/killing the wrong thing

            reviveCount[playerid] = 0;
        }
    }
}
I made some minor changes and added debugging, here's a picture.
https://prnt.sc/qm08km
https://prnt.sc/qm06g8
https://prnt.sc/qm06t4
Reply
#4

Quote:
Originally Posted by DomagojSellug
View Post
I made some minor changes and added debugging, here's a picture.
https://prnt.sc/qm08km
https://prnt.sc/qm06g8
https://prnt.sc/qm06t4
You modify the parameter and print its new value which is misleading. Move the debug message at the top and see for yourself or here is a sample of code:
pawn Code:
new timer_test;

main()
{
    timer_test = SetTimerEx("OnTestParameterValue", 500, true, "d", 1);
}

forward OnTestParameterValue(value);
public OnTestParameterValue(value)
{
    printf("OnTestParameterValue(%d);", value);
    value++;
   
    if (value == 5) KillTimer(timer_test);
}
Output is always the same:
pawn Code:
OnTestParameterValue(1);
.
.
.
OnTestParameterValue(1);
Reply
#5

Quote:
Originally Posted by Calisthenics
View Post
You modify the parameter and print its new value which is misleading. Move the debug message at the top and see for yourself or here is a sample of code:
pawn Code:
new timer_test;

main()
{
    timer_test = SetTimerEx("OnTestParameterValue", 500, true, "d", 1);
}

forward OnTestParameterValue(value);
public OnTestParameterValue(value)
{
    printf("OnTestParameterValue(%d);", value);
    value++;
   
    if (value == 5) KillTimer(timer_test);
}
Output is always the same:
pawn Code:
OnTestParameterValue(1);
.
.
.
OnTestParameterValue(1);
So... how should I edit my code in order to make it work?
Reply
#6

Quote:
Originally Posted by DomagojSellug
View Post
So... how should I edit my code in order to make it work?
You check and increase the variable `reviveCount[playerid]` in the callback.

I also mention about resetting label/time ids in my first post which is quite important.
Reply
#7

You could set the timer to not repeat, and then recreate the timer at the bottom each time it repeats.
Reply
#8

For some reason it always sets the target ID to 0, I don't know why. But whatever I do, it always attaches the label and handles everything with ID 0 which causes some weird bugs (e.g. if ID 0 is trying to revive ME, it'll show something random from another label e.g. "Use F to enter.")
Reply
#9

Code:
		RevivingText[playerid] = Create3DTextLabel("(( |--------- ))\nHELPING UP", COLOR_DARKGREEN, pX, pY, pZ, 25.0, -1, 0);

        reviveCount[playerid] = 0;
        reviveTextTimer[playerid] = SetTimerEx("updateRevivingText", 500, true, "d", playerid);

forward updateRevivingText(playerid);
public updateRevivingText(playerid)
{
	if(reviveCount[playerid] != 9)
	{
		switch(reviveCount[playerid])
		{
			case 0: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||-------- ))\nHELPING UP");
			case 1: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||------- ))\nHELPING UP");
			case 2: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||------ ))\nHELPING UP");
			case 3: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||----- ))\nHELPING UP");
			case 4: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||---- ))\nHELPING UP");
			case 5: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||--- ))\nHELPING UP");
			case 6: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||||-- ))\nHELPING UP");
			case 7: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||- ))\nHELPING UP");
			case 8: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||| ))\nHELPING UP");
		}
		reviveCount[playerid]++;
	}
	if(reviveCount[playerid] == 9)
	{
		Delete3DTextLabel(RevivingText[playerid]);
		reviveCount[playerid] = 0;
		KillTimer(reviveTextTimer[playerid]);
	}
	return 1;
}
Reply
#10

Quote:
Originally Posted by Radless
View Post
Code:
		RevivingText[playerid] = Create3DTextLabel("(( |--------- ))\nHELPING UP", COLOR_DARKGREEN, pX, pY, pZ, 25.0, -1, 0);

        reviveCount[playerid] = 0;
        reviveTextTimer[playerid] = SetTimerEx("updateRevivingText", 500, true, "d", playerid);

forward updateRevivingText(playerid);
public updateRevivingText(playerid)
{
	if(reviveCount[playerid] != 9)
	{
		switch(reviveCount[playerid])
		{
			case 0: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||-------- ))\nHELPING UP");
			case 1: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||------- ))\nHELPING UP");
			case 2: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||------ ))\nHELPING UP");
			case 3: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||----- ))\nHELPING UP");
			case 4: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||---- ))\nHELPING UP");
			case 5: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||--- ))\nHELPING UP");
			case 6: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( ||||||||-- ))\nHELPING UP");
			case 7: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||- ))\nHELPING UP");
			case 8: Update3DTextLabelText(RevivingText[playerid], COLOR_DARKGREEN, "(( |||||||||| ))\nHELPING UP");
		}
		reviveCount[playerid]++;
	}
	if(reviveCount[playerid] == 9)
	{
		Delete3DTextLabel(RevivingText[playerid]);
		reviveCount[playerid] = 0;
		KillTimer(reviveTextTimer[playerid]);
	}
	return 1;
}
That didn't help me with my issue though, my issue currently is that it's always setting the target ID to 0 for some reason...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)