Hello. I have written the following code which creates two players using a type and a function to get a player's health value.
The PlayerHealth(2) is supposed to return player two's health (in this case 60) but it is returning player one's health (100). Please help me correct it.
;Create first player
p.player=New player
p\prop.properties=New properties
p\prop\health=100
;Create second player
p.player=New player
p\prop.properties=New properties
p\prop\health=60
;
Print PlayerHealth(2)
WaitKey()
;
Type player
Field prop.properties
End Type
Type properties
Field health
End Type
;
Function PlayerHealth(player_number)
For p.player=Each player
count=count+1
If count=player_number Then
For p\prop.properties=Each properties
Return(p\prop\health) ;return health
Next
EndIf
Next
End Function
The PlayerHealth(2) is supposed to return player two's health (in this case 60) but it is returning player one's health (100). Please help me correct it.
;Create first player
p.player=New player
p\prop.properties=New properties
p\prop\health=100
;Create second player
p.player=New player
p\prop.properties=New properties
p\prop\health=60
;
Print PlayerHealth(2)
WaitKey()
;
Type player
Field prop.properties
End Type
Type properties
Field health
End Type
;
Function PlayerHealth(player_number)
For p.player=Each player
count=count+1
If count=player_number Then
For p\prop.properties=Each properties
Return(p\prop\health) ;return health
Next
EndIf
Next
End Function