Brackets (), [ ], { } What they are for.
2 posters
Operation Flashpoint Dragon Rising OFDR Forums :: OPERATION FLASHPOINT: DRAGON RISING :: OFDR EDITING :: TUTORIALS
Page 1 of 1
Brackets (), [ ], { } What they are for.
BRACKETS
There are three types that are used in the code that do different things. Such as:
("parenthesis") ----Parenthesis are used to denote arguments(or variables) passed to a function when calling it. They can containg any data type and must be used when calling a function. They are also used to section off or bundle parts of code, commonly used in math expressions like (5 * 2) + 1 to indicate that the product of 5 * 2 should be executed first and the one is added.
------------------------------------------
[hard brackets] ----These are used to denote an index in a table or an array. For example myTable[1] calls the value at the number 1 index with in the table myTable. While any data type can be used to index a table, the most common are numeric and string values. For our purposes you will almost always use those data types for indexing tables.
------------------------------------------
{"curly brackets"} ----The curly brackets always initialize a table. A table can be initialized empty or populated as shown here. Tables can contain any data type as shown in the second example below. It's important to note that an empty table is still a value. Even though the table contains no values, in an of itself it is still valued as an empty table.
myTable = {} --initializes an empty table assigned to the variable myTable
or they can be populated at the time of initialization like below.
myTable = {"stringValue1", 5, myVariable, true} --initializes a populated table assigned to the variable myTable
They can be quite handy and useful once you get the hang of it. You can eventually control a mulitude of events just by using tables in your code.
------------------------------------------
All of these usually contain strings, variables or numbers; or a mixture of all three. In the OFP script command onMount(vehicleName, unitName, echelonName) the parenthesis here contains variables we can use or refer to when using our commands in the rest of the chunk.
There are three types that are used in the code that do different things. Such as:
("parenthesis") ----Parenthesis are used to denote arguments(or variables) passed to a function when calling it. They can containg any data type and must be used when calling a function. They are also used to section off or bundle parts of code, commonly used in math expressions like (5 * 2) + 1 to indicate that the product of 5 * 2 should be executed first and the one is added.
------------------------------------------
[hard brackets] ----These are used to denote an index in a table or an array. For example myTable[1] calls the value at the number 1 index with in the table myTable. While any data type can be used to index a table, the most common are numeric and string values. For our purposes you will almost always use those data types for indexing tables.
------------------------------------------
{"curly brackets"} ----The curly brackets always initialize a table. A table can be initialized empty or populated as shown here. Tables can contain any data type as shown in the second example below. It's important to note that an empty table is still a value. Even though the table contains no values, in an of itself it is still valued as an empty table.
myTable = {} --initializes an empty table assigned to the variable myTable
or they can be populated at the time of initialization like below.
myTable = {"stringValue1", 5, myVariable, true} --initializes a populated table assigned to the variable myTable
They can be quite handy and useful once you get the hang of it. You can eventually control a mulitude of events just by using tables in your code.
------------------------------------------
All of these usually contain strings, variables or numbers; or a mixture of all three. In the OFP script command onMount(vehicleName, unitName, echelonName) the parenthesis here contains variables we can use or refer to when using our commands in the rest of the chunk.
Last edited by tvig0r0us on Tue 18 Dec 2012, 23:11; edited 2 times in total (Reason for editing : Corrections)
Re: Brackets (), [ ], { } What they are for.
nice explanation - was always suspicious about those curly brackets they always looked very mustache-e to me
:{
:{
Last edited by JohnStevens on Wed 19 Dec 2012, 21:27; edited 1 time in total
John J. Stevens- Admin
- Location : WV/PA
Points : 285
Reputation : 22
Join date : 2012-12-19
Operation Flashpoint Dragon Rising OFDR Forums :: OPERATION FLASHPOINT: DRAGON RISING :: OFDR EDITING :: TUTORIALS
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|