Hi,
This is a tutorial on how to handle a set data.
Imagine, your game must manipulate data of players, each player in possesses own data,
Array are useful for retrieving information about a player, but multiple players is harder...
Warning, you need to know create a Array and be able to create a function that displays the contents of the Array before you can follow this tutorial !
you have an example here >
Arrays
(to you to rewrite the tutorial either sourcecode or logicblock)
I create a Array containing data of the first player, I'll rename "structure 1"
then for the player2 and for the player3 and a special structure I rename "new_structure",
it will serve to add new players...
e.g,
***Structure1***
Name = ViraX
Level = Undetermined
Location = France
****************
***Structure2***
Name = Newbie
Level = 3
Location = USA
****************
***Structure3***
Name = Player3
Level = 80
Location = Earth
****************
***New_Structure***
Name = TEST
Level = TEST
Location = TEST
******************
<Array name="structure1">
<SetArray name="structure1" posX="0" value=" NAME: ViraX"/>
<SetArray name="structure1" posX="1" value=" LVL: Undetermined"/>
<SetArray name="structure1" posX="2" value=" LOCATION: France"/>
</Array>
<Array name="structure2">
<SetArray name="structure2" posX="0" value=" NAME: Newbie"/>
<SetArray name="structure2" posX="1" value=" LVL: 3"/>
<SetArray name="structure2" posX="2" value=" LOCATION: USA"/>
</Array>
<Array name="structure3">
<SetArray name="structure3" posX="0" value=" NAME: Player3"/>
<SetArray name="structure3" posX="1" value=" LVL: 80"/>
<SetArray name="structure3" posX="2" value=" LOCATION: Earth"/>
</Array>
<Array name="new_structure">
<SetArray name="new_structure" posX="0" value=" NAME: TEST"/>
<SetArray name="new_structure" posX="1" value=" LVL: TEST"/>
<SetArray name="new_structure" posX="2" value=" LOCATION: TEST"/>
</Array>
I get 3 Arrays, a Array by a player, Okay ?!
Now, I create a new Array, that'll contain these structures, I renamed it "my_array".
(do not insert "new_structure")
<Array name="my_array">
<SetArray name="my_array" posX="0" value="structure1"/>
<SetArray name="my_array" posX="1" value="structure2"/>
<SetArray name="my_array" posX="2" value="structure3"/>
</Array>
If you are not lost, I continuous,
I create a function that read the contents of "my_array",
I give you the code of my function "READ", in "Pseudo-Code" :
<Var 'i' = 0>
<LABEL1>
<LABEL1>
<FONCTION READ>
<LOOP>
<WAIT '2'>
<INCREMENT i += 1>
<IF i == "my_array.length">
<Set i = 0>
<IF END>
<Set LABEL1.text = "PLAYERS> +my_array[i]"
<WAIT>
<LOOP END>
<FONCTION>
<CALL READ>
<CALL>
the function "READ" displays complete information about every player ...
Here we created our dataset !
it's cool but it would be better if we could handled our structures ...
for example, add a new player.
to add a new player, add a new structure in our array, assign its "PosX" and its value ...
but imagine 100 players come to your game, you have to create in advance 100 structures ? this is not serious
I'll create a function that will insert a new structure automatically,
and as many times as I want and giving it its "PosX" automatically.
I have to know in advance how many structures already has our Array,
otherwise I might insert a structure instead of another, and then will be messy if I give a "PosX" randomly each time ...
I will first create a function that returns me the size of my Array "my_array".
so I know how many structures there in my Array, and also assign a "PosX" for each new structure.
here is my function "LEN" which returns me the size of "my_array" in a variable "return_len",
all the time.
<Var var="return_len" value="0"/>
<Function name="len" isCollapse="0">
<Loop>
<If var="return_len" ne="my_array.length">
<Increment var="return_len" value="1"/>
<ElseIf var="return_len" eq="my_array.length">
<Set var="return_len" value="return_len"/>
</ElseIf>
</If>
</Loop>
</Function>
Now, I can create my "PUSH" function that automatically insert a new player.
<Function name="push">
<SetArray name="my_array" value="new_structure" posX="return_len"/>
</Function>
To be able to call my function "PUSH", I have to make this :
<Timeout seconds="1">
<Call funcName="push"/>
</Timeout>
You can check the insertion through our function "READ" ...
to remove a player,
we can not destroy a structure or array, but we can reset to NULL,
with function "POP_ID".
<Var var="i_pop" value="0"/>
<Var var="id_target" value="2"/> //COMMENT: it is for you to add the id (posX) of the players you want
<Function name="pop_id">
<Loop>
<If var="i_pop" eq="my_array.length">
<Set var="i_pop" value="0"/>
</If>
<Increment var="i_pop" value="1"/>
<If var="i_pop" eq="id_target">
<SetArray name="my_array" posX="id_target" value="NULL"/>
</If>
</Loop>
</Function>
Check on its reset with "READ" ...
These are the main manipulation, I continued to add other functions later in this tutorial,
I do not speak English,if you think do a better translation for this tutorial, send me a private message.
*UPDATE1
+ modification (little) translation .
+ the function 'PUSH' do not insert a new structure but a simple data, now she insert a new structure !