Unknown_Hero Mage
![Mage Mage](https://i.imgur.com/T6XfYnc.gif)
![Unknown_Hero](https://i.imgur.com/f6yn7Vg.png)
Messages : 780 Quality Points : 78 Registration Date : 2015-09-06
![[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Empty](https://2img.net/i/empty.gif) | Subject: [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" 2018-09-27, 00:00 | |
| I'm trying to understand how it works. ![Smile](/users/1112/86/44/25/smiles/3275789839.gif) On the Scripting Documentation page: GetCurrentPlayer() Returns a number (0-5) determining which player is active now. GetHeroOwner(hero) hero: The hero to get the owner of. (See, for example, GetHero). Returns the owner of the given hero as an integer (0-5), or -1 if the hero is not owned by any player (i.e.: is or may become available for hire). I did some tests. This does not work: - Code:
-
function OnHeroMove(x, y) player = GetCurrentPlayer(); if player == 0 then MessageBox("Player is 0."); elseif player == 1 then MessageBox("Player is 1."); end; end This works: - Code:
-
function OnHeroMove(x, y) hero = GetCurrentHero(); owner = GetHeroOwner(hero); if owner == 0 then MessageBox("Owner is 0."); elseif owner == 1 then MessageBox("Owner is 1."); end; end This works: - Code:
-
function OnHeroMove(x, y) player = GetCurrentPlayer(); gold = GetResource(player, RESOURCE_GOLD); gold = gold - 500; SetResource(player, RESOURCE_GOLD, gold); MessageBox("Player - 500 gold."); end This does not work: - Code:
-
function OnHeroMove(x, y) hero = GetCurrentHero(); player = GetHeroOwner(hero); gold = GetResource(player, RESOURCE_GOLD); gold = gold - 500; SetResource(player, RESOURCE_GOLD, gold); MessageBox("Player - 500 gold."); end So, what is the difference between the two expressions and why it works in one case and not in the other? Is this normal? It would be nice if someone could tell me. ![Very Happy](/users/1112/86/44/25/smiles/3489818386.png) | |
|
Darmani Master Modder
![Master Modder Master Modder](https://i.imgur.com/IpF8FfL.gif)
![Darmani](https://2img.net/u/1112/86/44/25/avatars/170-23.png)
Messages : 289 Quality Points : 47 Registration Date : 2014-12-27
![[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Empty](https://2img.net/i/empty.gif) | Subject: Re: [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" 2018-12-31, 15:59 | |
| The reason is that GetCurrentPlayer returns a player object, while GetHeroOwner returns a number. So, the documentation is incorrect. GetCurrentPlayer().color or GetPlayerColor(GetCurrentPlayer()) should do what you want it to do. It looks like this is a change that occurred during the scripting overhaul to deep-binding.
I will make it so GetHeroOwner also returns a player object, and update the documentation of both. | |
|
Darmani Master Modder
![Master Modder Master Modder](https://i.imgur.com/IpF8FfL.gif)
![Darmani](https://2img.net/u/1112/86/44/25/avatars/170-23.png)
Messages : 289 Quality Points : 47 Registration Date : 2014-12-27
![[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Empty](https://2img.net/i/empty.gif) | Subject: Re: [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" 2019-01-01, 12:01 | |
| This has been done. Both examples now work using "player.color == 0" . | |
|
Unknown_Hero Mage
![Mage Mage](https://i.imgur.com/T6XfYnc.gif)
![Unknown_Hero](https://i.imgur.com/f6yn7Vg.png)
Messages : 780 Quality Points : 78 Registration Date : 2015-09-06
![[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Empty](https://2img.net/i/empty.gif) | Subject: Re: [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" 2019-01-03, 07:06 | |
| Thanks for the explanation and the change. ![Smile](/users/1112/86/44/25/smiles/3275789839.gif) | |
|
Sponsored content
![[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Empty](https://2img.net/i/empty.gif) | Subject: Re: [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" ![[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitime](https://2img.net/i/fa/icon_minitime.gif) | |
| |
|