ClayPigeon
Member
Posts: 214
Threads: 13
Joined: Mar 2012
Reputation:
8
|
RE: The "for"
for(VARIABLE; TERM; ACTION)
That does an ACTION every time the TERM that is connected to the VARIABLE is true.
A classic loop in HPL will be: (in C/C++ the integer usually starts of 0, not 1)
for(int i = 1; i < 11; i++)
{
CODE;
}
Actually, we're firstly defining the integer 'i' by doing int i and giving it a value of 1.
Secondly, we're checking if 'i' is smaller than 11(can be anything than 11). If it is, the code goes into the brackets ( {, } ) and performs the CODE that is in there. then it goes back and does the ACTION, that in our case promotes 'i' by 1.
Next, 'i' will be 2, as we added 1, since 2 is smaller than 11 the loop will perform again and again until i will be worth 11 and the code won't read the CODE inside the brackets.
for(int i = 1; i < 13; i++)
{
AddEnemyPatrolNode("servant_grunt_1", "patrol_node_"+i, 0.2f, "");
}
That classic code will add every patrol node between 1 and 12, by calling:
patrol_node_+1 = patrol_node_1
patrol_node_+2 = patrol_node_2
etc.
|
|
03-23-2012, 10:49 PM |
|