[Squirrel] Textdraw within an array within a class within an array.

Started by Thijn, Aug 03, 2015, 03:25 PM

Previous topic - Next topic

Thijn

I've noticed text draws aren't liking arrays within classes. The following snippet will demonstrate this:
class drawClass {
textDraws = array(1,null);
textDraw = null;
}

drawInfo <- array(2, null);

function onScriptLoad()
{
drawInfo[ 0 ] = drawClass();
drawInfo[ 1 ] = drawClass();

drawInfo[ 0 ].textDraws[0] = CreateTextdraw("Test text", 50, 50, 0xFFFFFFFF);
print( drawInfo[ 0 ].textDraws[0] );
print( drawInfo[ 1 ].textDraws[0] );

drawInfo[ 1 ].textDraws[0] = CreateTextdraw("Test text 2", 50, 50, 0xFFFFFFFF);
print( drawInfo[ 0 ].textDraws[0] );
print( drawInfo[ 1 ].textDraws[0] );

print(" ---- ");

drawInfo[ 0 ].textDraw = CreateTextdraw("Test text", 50, 50, 0xFFFFFFFF);
print( drawInfo[ 0 ].textDraw );
print( drawInfo[ 1 ].textDraw );

drawInfo[ 1 ].textDraw = CreateTextdraw("Test text 2", 50, 50, 0xFFFFFFFF);
print( drawInfo[ 0 ].textDraw );
print( drawInfo[ 1 ].textDraw );
}

This will produce the follow output:
Quote[SCRIPT]  (instance : 0x000000ABB94F38F0)
[SCRIPT]  (instance : 0x000000ABB94F38F0)
[SCRIPT]  (instance : 0x000000ABB94F12E0)
[SCRIPT]  (instance : 0x000000ABB94F12E0)
[SCRIPT]   ----
[SCRIPT]  (instance : 0x000000ABB94F38F0)
[SCRIPT]  (null : 0x0000000000000000)
[SCRIPT]  (instance : 0x000000ABB94F38F0)
[SCRIPT]  (instance : 0x000000ABB94F0EF0)

As you can see, the textdraw stored in the array on the first slot, will somehow duplicate itself on the second slot.
In my current script I'm deleting the stored textdraw for a player (e.g. slot 2), and recreate it with another text only showing it for player 2. This will remove the textdraw for anyone else, until someone else gets a redraw. That person gets the textdraw, the rest does not.

Since I want to draw around 3 textdraws for each player, I need to add 3 different members to the player class to get this to work. Instead of a simple array, which I can simply iterate over.

Any suggestions are appreciated :)

DizzasTeR

Quote from: Thijn on Aug 03, 2015, 03:25 PMSince I want to draw around 3 textdraws for each player, I need to add 3 different members to the player class to get this to work. Instead of a simple array, which I can simply iterate over.

Well, using the same thing here, adding members to a class and then assigning them the createtextdraw for specific players...

Gudio


Thijn