~ Forums of Enroth ~
Would you like to react to this message? Create an account in a few clicks or log in to continue.

~ Forums of Enroth ~

The Enroth diehard fan community
 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  
Latest topics
» [H3SW 0.8.2] Spicy Delivery
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitimeby DanilaRud015 2024-07-25, 23:37

» ...to XP run...
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitimeby Darmani 2024-07-18, 21:34

» fheroes2 General Announcements
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitimeby sirDranik 2024-07-15, 00:28

» Silence of the Siren (HoMM like scifi game)
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitimeby Sir Albe 2024-07-13, 08:09

» Songs of Silence (HoMM like game)
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitimeby Blake01 2024-07-07, 21:12

» Lego Heroes of Might & Magic
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitimeby Blake01 2024-07-07, 21:00

» 5Kings1Ring
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitimeby GodRage 2024-07-01, 10:33

Poll
Global announcements should be:
Everlasting, 1 for each project.
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Redbar110%[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Redbar12
 0% [ 0 ]
Temporary, when there is something new to announce.
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Redbar11100%[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Redbar12
 100% [ 6 ]
Holalala... No idea where the Ultimate artifact is.
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Redbar110%[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Redbar12
 0% [ 0 ]
Total Votes : 6
Most Viewed Topics
H3SW: General Graphics discussion
Ragoon's Graphics For HoMM3SW
Introduce yourself
H3SW General Discussion
H3SW Map List: Work in progress
H3SW: Dwelling Development
Forum Admins Feed
The Floody Land
Enrothian Fan Art
Heroes III: The Succession Wars v0.8.2 Beta

 

 [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)"

Go down 
2 posters
AuthorMessage
Unknown_Hero
Mage
Mage
Unknown_Hero


Messages : 780
Quality Points : 78
Registration Date : 2015-09-06

[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Empty
PostSubject: [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)"   [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitime2018-09-27, 00:00

I'm trying to understand how it works. Smile

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
Back to top Go down
Darmani
Master Modder
Master Modder
Darmani


Messages : 289
Quality Points : 47
Registration Date : 2014-12-27

[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Empty
PostSubject: Re: [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)"   [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitime2018-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.
Back to top Go down
Darmani
Master Modder
Master Modder
Darmani


Messages : 289
Quality Points : 47
Registration Date : 2014-12-27

[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Empty
PostSubject: Re: [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)"   [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitime2019-01-01, 12:01

This has been done. Both examples now work using "player.color == 0" .
Back to top Go down
Unknown_Hero
Mage
Mage
Unknown_Hero


Messages : 780
Quality Points : 78
Registration Date : 2015-09-06

[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Empty
PostSubject: Re: [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)"   [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitime2019-01-03, 07:06

Thanks for the explanation and the change. Smile
Back to top Go down
Sponsored content





[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Empty
PostSubject: Re: [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)"   [Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)" Icon_minitime

Back to top Go down
 
[Ironfist ver 1.3.0] "GetCurrentPlayer()" and "GetHeroOwner(hero)"
Back to top 
Page 1 of 1
 Similar topics
-
» [Ironfist ver 1.2] TakeArtifact(hero, artifact)
» [Ironfist ver 1.3.0] Bug the number of creatures in the hero's army changes at the beginning of new turn
» [Ironfist ver 1.3.0] Problem with SetPrimarySkill(hero, skill, quantity) and OnBattleStart()
» [Heroes 2 AI Flaws] AI Hero Attacks Human Ally Hero
» [Ironfist ver 1.2] Ironfist Editor - Where is my mouse?

Permissions in this forum:You cannot reply to topics in this forum
~ Forums of Enroth ~ :: Modding Guild :: Heroes of Might and Magic II: Project Ironfist :: Modding and Mapmaking-
Jump to: