Well, i'm thinking since a few days to increase my knowledge of variables, i've gone through Global variables, such as bla <- 0; and etc.
plus the arrays bla=false;
So, i've been thinking about this []
I don't know even what it is called! just curious to know the functions, mean how it is exactly used, and with examples, uhm i've seen it in a few snippets or script, so i'm curious to know the functions with examples, and the name of it, please tell it, it can be useful for me.
P.S: Sorry, for my bad english, and correct me if i'm wrong that bla = false;
isn't called an array.
[] is shorthand for an empty array. You can also declare a prefilled array like this:
local arr = [0, 1, -1, 7, 400];
That will create an array containing five integers in that order.
local arr = [7];
That will create an array of one element, only containing the number 7.
Quote from: Stormeus on Feb 01, 2016, 09:59 AM[] is shorthand for an empty array. You can also declare a prefilled array like this:
local arr = [0, 1, -1, 7, 400];
That will create an array containing five integers in that order.
local arr = [7];
That will create an array of one element, only containing the number 7.
I've seen like
bla <- [];
local Bla = FindPlayer( Bla );
bla.push(Bla.ID)
So may you also describe push, and remove functions, else it's all clear now :) mean how enter, and how can i see that how much of them are enter, and etc.
anyway Thanks :)
local bla = false;
That is a bool and, not an array. Boolean variables are either true or false.
first: bla = Noobcake, Doob
bla.push("Nububub");
bla = Nububub, Noobcake, Doob
bla.remove(2);
bla = Nububub, Doob
@NE.CrystalBlue that is the worst example I've ever seen.
@[TBS]Destroyer, This might help you understand. I see you are mixing things up, I've taken a few moments to write this so you may know what is what.
local variable = "This is a local variable holding a string";
globalVariable <- "This is a global variable holding a string";
local myStaticArray = [ ];
local myDynamicArray = array( 9, null ); // Create an array of 10 slots ( 0 - 9 = 10 ) each having nothing ( null )
local myTable = { someValue = 23 } // A local table.
// Now using these to store / delete data.
local someData = "Nickname";
myStaticArray.push( someData );
myDynamicArray[ 0 ] = someData;
print( myStaticArray[ 0 ] + " // Static Array" ) // -> "Nickname";
print( myDynamicArray[ 0 ] + " // Dynamic Array" ) // -> "Nickname";
myStaticArray.remove( 0 ) // -> remove any data at index 0, we inserted 'someData' at 0
myDynamicArray[ 0 ] = null; // Remove any data at index 0 ( Set it to null );
myTable.rawset( 1, someData );// -> At index 1 of myTable insert 'someData'.
foreach( index, value in myTable )
{
print( "Index: " + index + " | Value: " + value + " // Table" );
}
print( myTable.someValue + " //Table's value" ) // -> outputs the value of 'someValue' which we pre-defined on creation of this table.
myTable.rawdelete( 0 ) // We
myTable.rawdelete( 1 ) // Deleted all the data held on those two indexes and now the table is empty.
and the outputs:-
[SCRIPT] Nickname // Static Array
[SCRIPT] Nickname // Dynamic Array
[SCRIPT] Index: someValue | Value: 23 // Table
[SCRIPT] Index: 1 | Value: Nickname // Table
[SCRIPT] 23 //Table's value
Quote from: Doom_Kill3R on Feb 01, 2016, 01:53 PM@NE.CrystalBlue that is the worst example I've ever seen.
@[TBS]Destroyer, This might help you understand. I see you are mixing things up, I've taken a few moments to write this so you may know what is what.
local variable = "This is a local variable holding a string";
globalVariable <- "This is a global variable holding a string";
local myStaticArray = [ ];
local myDynamicArray = array( 9, null ); // Create an array of 10 slots ( 0 - 9 = 10 ) each having nothing ( null )
local myTable = { someValue = 23 } // A local table.
// Now using these to store / delete data.
local someData = "Nickname";
myStaticArray.push( someData );
myDynamicArray[ 0 ] = someData;
print( myStaticArray[ 0 ] + " // Static Array" ) // -> "Nickname";
print( myDynamicArray[ 0 ] + " // Dynamic Array" ) // -> "Nickname";
myStaticArray.remove( 0 ) // -> remove any data at index 0, we inserted 'someData' at 0
myDynamicArray[ 0 ] = null; // Remove any data at index 0 ( Set it to null );
myTable.rawset( 1, someData );// -> At index 1 of myTable insert 'someData'.
foreach( index, value in myTable )
{
print( "Index: " + index + " | Value: " + value + " // Table" );
}
print( myTable.someValue + " //Table's value" ) // -> outputs the value of 'someValue' which we pre-defined on creation of this table.
myTable.rawdelete( 0 ) // We
myTable.rawdelete( 1 ) // Deleted all the data held on those two indexes and now the table is empty.
and the outputs:-
[SCRIPT] Nickname // Static Array
[SCRIPT] Nickname // Dynamic Array
[SCRIPT] Index: someValue | Value: 23 // Table
[SCRIPT] Index: 1 | Value: Nickname // Table
[SCRIPT] 23 //Table's value
This is what i called An
ASTOUNDING Explainer thou, Thank you <:
, but i've one question
i've made a Static Array for testing
Test = [ ];
I also pushed my name, or any players name when it joins
Test.push[player.ID];
so, I thought to get the Names of what is store in it, by making a command with this function
foreach( index, value in Test )
{
ClientMessageToAll( "Index:" + value + "",255,255,0 );
}
I know, i'm actually trying to get the value over, but! I also tried using Index to get the names, but i didn't got, I want to know the reason why?
It's just gives Index:0
You have made a mistake, this won't work:
Test.push[player.ID];
Why? because you don't have to use square brackets in push instead you need to use the normal brackets '( and )' so it should be:
Test.push( player.ID );
Now when you want to get the names of all players stored in that array, read this code carefully.
foreach( index, value in Test )
{
local Player = FindPlayer( value ); // Remember you pushed 'player.ID' so ofcourse if we have an ID we get the instance of the player using FindPlayer( integer_ID_of_Player )
// Now that we have the player's instance stored in 'Player' we can use the 'Name' method.
ClientMessageToAll( "Index: " + index + " | Player ID: " + value + " | Player Name: " + Player.Name, 255, 255, 0 );
}
and ofcourse you will get the following output:-
Index: 0 | Player ID: 0 | Player Name: Player's_Name_Here
Its as simple as that.
Quote from: Doom_Kill3R on Feb 01, 2016, 03:21 PMYou have made a mistake, this won't work:
Test.push[player.ID];
Why? because you don't have to use square brackets in push instead you need to use the normal brackets '( and )' so it should be:
Test.push( player.ID );
Now when you want to get the names of all players stored in that array, read this code carefully.
foreach( index, value in Test )
{
local Player = FindPlayer( value ); // Remember you pushed 'player.ID' so ofcourse if we have an ID we get the instance of the player using FindPlayer( integer_ID_of_Player )
// Now that we have the player's instance stored in 'Player' we can use the 'Name' method.
ClientMessageToAll( "Index: " + index + " | Player ID: " + value + " | Player Name: " + Player.Name, 255, 255, 0 );
}
and ofcourse you will get the following output:-
Index: 0 | Player ID: 0 | Player Name: Player's_Name_Here
Its as simple as that.
o.0 Really, you explain, so good, Thank you, but lol if you don't mind please answer this last question
Instance = player Whole Info?
Such as, ID, and etc.
Quote from: [TBS]Destroyer on Feb 01, 2016, 03:30 PMQuote from: Doom_Kill3R on Feb 01, 2016, 03:21 PMYou have made a mistake, this won't work:
Test.push[player.ID];
Why? because you don't have to use square brackets in push instead you need to use the normal brackets '( and )' so it should be:
Test.push( player.ID );
Now when you want to get the names of all players stored in that array, read this code carefully.
foreach( index, value in Test )
{
local Player = FindPlayer( value ); // Remember you pushed 'player.ID' so ofcourse if we have an ID we get the instance of the player using FindPlayer( integer_ID_of_Player )
// Now that we have the player's instance stored in 'Player' we can use the 'Name' method.
ClientMessageToAll( "Index: " + index + " | Player ID: " + value + " | Player Name: " + Player.Name, 255, 255, 0 );
}
and ofcourse you will get the following output:-
Index: 0 | Player ID: 0 | Player Name: Player's_Name_Here
Its as simple as that.
o.0 Really, you explain, so good, Thank you, but lol if you don't mind please answer this last question
Instance = player Whole Info?
Such as, ID, and etc.
Yup.
Uhm Thanks everyone, Special Sir.#Doom :) Topic locked.