What's a good method to returning player's nicknames with a GUILabel?

Started by D4rkR420R, Aug 04, 2018, 09:19 PM

Previous topic - Next topic

D4rkR420R

As the title describes it, I tried firstly storing data into variables, then, I'd like to output a variable storing a text which was before an array, but I separated the items in the array using the JoinArray function. However, the GUILabel ignored the escape characters and threw out the whole text in a line.

screen <- GUI.GetScreenSize();
Players1 <- null;
Players2 <- null;
CPlayers <- [ "Bob", "Jerry", "Tom", "TotalNoob" ]; // Pretend this variables existed
CPlayers2 <- [ "Mary", "Bryan", "Billy", "Michael" ]; //  in the server side.

function Script::ScriptLoad()
::Players1 = JoinArray( CPlayers, "\n" );
::Players2 = JoinArray( CPlayers2, "\n" );
Console.Print( ::Players1 ); // Should print out the text indented after the item.
        Label <- GUILabel( VectorScreen( ( screen.X * 0.80 ), ( screen.Y * 0.43 ) ), Colour( 255, 255, 255 ), ::Players1 ); // Doesn't indent the text
}

So, I ask again, what's a good method to return the player's nicknames stored in the CPlayers array, but indented, in a GUILabel? I don't like the way of creating multiple variables to store player's name.

Xmair

::Players1 = JoinArray( CPlayers,"\n" );
Label <- GUILabel( VectorScreen( ( screen.X * 0.80 ), ( screen.Y * 0.43 ) ), Colour( 255, 255, 255 ), ::ClanPlayers1 );
You used ClanPlayers1 instead of Players1.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

D4rkR420R

Quote from: Xmair on Aug 05, 2018, 05:36 AM::Players1 = JoinArray( CPlayers,"\n" );
Label <- GUILabel( VectorScreen( ( screen.X * 0.80 ), ( screen.Y * 0.43 ) ), Colour( 255, 255, 255 ), ::ClanPlayers1 );
You used ClanPlayers1 instead of Players1.

My bad, I was copy-and-pasting here and rewriting an example.


!

Quote from: KuRuMi^ on Aug 07, 2018, 05:03 AMBump.
CPlayers <- [ "Bob", "Jerry", "Tom", "TotalNoob" ];
CPlayers2 <- [ "Mary", "Bryan", "Billy", "Michael" ];

function Script::ScriptLoad() {
Console.Print( returnString( CPlayers ) );
Label <- GUILabel( VectorScreen( 0, 0 ), Colour( 255, 255, 255 ), returnString( CPlayers ) );
}

function returnString( arr ) {
local str = null;
foreach( iStr in arr ) {
( !str ? ( str = iStr ) : ( str += ", "+iStr ) );
}

return str;
}

Discord: zeus#5155

D4rkR420R

Quote from: ! on Aug 07, 2018, 08:51 AM
Quote from: KuRuMi^ on Aug 07, 2018, 05:03 AMBump.
CPlayers <- [ "Bob", "Jerry", "Tom", "TotalNoob" ];
CPlayers2 <- [ "Mary", "Bryan", "Billy", "Michael" ];

function Script::ScriptLoad() {
Console.Print( returnString( CPlayers ) );
Label <- GUILabel( VectorScreen( 0, 0 ), Colour( 255, 255, 255 ), returnString( CPlayers ) );
}

function returnString( arr ) {
local str = null;
foreach( iStr in arr ) {
( !str ? ( str = iStr ) : ( str += ", "+iStr ) );
}

return str;
}

Is it not possible to indent the text due to the GUILabel's associativity? I'd like to have a vertical list of players.

vitogta

Quote from: KuRuMi^ on Aug 07, 2018, 03:58 PM
Quote from: ! on Aug 07, 2018, 08:51 AM
Quote from: KuRuMi^ on Aug 07, 2018, 05:03 AMBump.
CPlayers <- [ "Bob", "Jerry", "Tom", "TotalNoob" ];
CPlayers2 <- [ "Mary", "Bryan", "Billy", "Michael" ];

function Script::ScriptLoad() {
Console.Print( returnString( CPlayers ) );
Label <- GUILabel( VectorScreen( 0, 0 ), Colour( 255, 255, 255 ), returnString( CPlayers ) );
}

function returnString( arr ) {
local str = null;
foreach( iStr in arr ) {
( !str ? ( str = iStr ) : ( str += ", "+iStr ) );
}

return str;
}

Is it not possible to indent the text due to the GUILabel's associativity? I'd like to have a vertical list of players.
players <- {};
players.rawset("noob", 123); // writes 123
players.rawget("noob"); // returns 123
https://developer.electricimp.com/squirrel/table
table.clear() — Removes all of the items from a table
table.getdelegate() — Returns a table's delegate
table.len() — Returns the number of slots in a table
table.rawdelete() — Deletes a key-value pair from a table without employing delegation
table.rawget() — Retrieves the value of the specified key without employing delegation
table.rawin() — Checks for the presence of the specified key in the table without employing delegation
table.rawset() — Sets the value of the specified key without employing delegation
table.setdelegate() — Specifies a table's delegate