• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Trigger works for the first time, but not the second time

Status
Not open for further replies.
Level 9
Joined
Jul 30, 2018
Messages
445
Hey!

There must be a very simple solution to this, but for some reason I don't get it. So, the idea is that there can only be one Capital (a research at level 4), thus when you research it, it should set all other research levels (i.e. the last Capital) back to level 3, so the new researched research is the new Capital. It works fine this far, but when I try to research the old Capital back, it just runs the Finish Research trigger right away and doesn't increase the research level for it.

Here's the trigger:
  • Finish Research
    • Events
      • Unit - A unit Finishes research
    • Conditions
    • Actions
      • Game - Display to DebugPlayers the text: (Running Trigger: + (Name of the current trigger))
      • For each (Integer LoopIntFinishResearch[0]) from 1 to PlayerCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Triggering unit)) Equal to Player[LoopIntFinishResearch[0]]
            • Then - Actions
              • Set PlayerIndex = LoopIntFinishResearch[0]
              • Set CityIndex = (Unit: (Triggering unit)'s Integer Field: Gold Bounty Awarded - Base ('ubba'))
              • -------- Check if Capital is being built --------
              • Set TempResearch[0] = ResearchTownHall[CityIndex]
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Researched tech-type) Equal to TempResearch[0]
                  • (Current research level of TempResearch[0] for Player[PlayerIndex]) Equal to 4
                • Then - Actions
                  • Player - Set the current research level of ResearchCurrentCapital[PlayerIndex] to 3 for Player[PlayerIndex]
                  • Set ResearchCurrentCapital[PlayerIndex] = (Researched tech-type)
                • Else - Actions
            • Else - Actions
I also uploaded the whole map, if you want to play around. You can test this by first upgrading one city to Capital, and then upgrading another to replace the first Capital. Again, works this far, but when trying to upgrade the old city back to Capital, it doesn't work.

Thanks for the answers in advance! :D
 

Attachments

  • HeroesOfWarAndCraft v0.0.013.w3x
    202.8 KB · Views: 30
Level 17
Joined
Mar 21, 2011
Messages
1,597
Is it even possible to downgrade research types? i never worked with them.
What exactly happens when you try to upgrade another town hall to level 4? Does the current level 4 town hall stay at 4?
Also, why do you use arrays for your loop index and tempresearch? And why do you use a loop in the first place?
 
Level 9
Joined
Jul 30, 2018
Messages
445
Is it even possible to downgrade research types?

Yes. As I said, it works fine for the first time in my case.

What exactly happens when you try to upgrade another town hall to level 4? Does the current level 4 town hall stay at 4?

When I research Capital in Town A, it works just as it should and the other research downgrades in Town 2, just as it should. But when I try to research the Capital back in Town 2, it just immediately says "Research Complete" and nothing happens, except that the money is lost.

Also, why do you use arrays for your loop index and tempresearch? And why do you use a loop in the first place?

I use loops because I have many towns (and each town has actually 4 different units, because I want them to have multiple pages of command buttons) and many players and I don't want to make own trigger for every single town and for every single player (because researches are player-specific, so I have to kind of fake that they would be town-specific instead). It's actually a pretty hard and complex concept, so you get a lot better idea by trying the map. :D

Edit: Also, as for why I get the player in a loop, rather than using just Player(X) I have saved players to custom variables Player[1], Player[2], etc, because I don't use all colors in the default order.
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,019
Err... how are we supposed to build another capital? I don't see any builder units. I did notice that if I ended my turn while researching anything the first thing currently being researched would be instantly completed; did you intend that?
 
Level 9
Joined
Jul 30, 2018
Messages
445
Err... how are we supposed to build another capital? I don't see any builder units. I did notice that if I ended my turn while researching anything the first thing currently being researched would be instantly completed; did you intend that?

So yeah, the "buildings" are not actual buildings, but researches the building researches. And yes, it is intentional that the building gets always completed at the start of the next turn.
 
Level 39
Joined
Feb 27, 2007
Messages
5,019
I didn't try attacking the buildings to gain ownership before. I see now.

I delved further, and it turns out the 'research and end of turn' thing is actually a problem. Try this: complete researching Great Hall, then end your turn. Before you click end turn the next available research shows Town Hall properly, but once you click end turn it changes to City Hall, magically increasing the research level by 1. Ending your turn repeatedly after this does not progress the research any further.

A second test: complete researching City Hall, complete researching Improved Defenses, then end your turn. After ending the turn the next available defense level is Imbued so the Advanced tier was auto-researched; however, the City Hall did not get auto-researched to Capital. Thus only the last researched tech on your turn will be +1'd. Interestingly, these levels go up even if the requirement to do so is not met (Advanced requires great hall but still goes up to imbued). Knowing how this was messing with research levels (and possibly auto-researching Capital) and working around it to avoid such a bug still only brought me to the exact same scenario as you experienced with the instant research that does nothing, so this isn't the cause of the issue.

The issue is that upgrades cannot be unresearched; wc3 simply doesn't support it. Research currently at level N can be set to level M such that M>N (can skip levels 'up') but not if M<N (can't go 'down' at all or you get this weird behavior). If you can get past cohadar being a total dick (which he was pretty much all of the time) this thread has a breakdown of the only 'workaround' of sorts and I don't think it will work for you: [Solved] - Setting research back to 0? I didn't try to see what happens if you capture a city while it's upgraded (do/should you get it at its current upgrade level or back at the lowest level?) but if you want any reversibility there upgrades are not going to work at all. For any of your techs.

I think the best option for you here would to actually treat those specific techs as upgrades to the main building instead, since those can be undone by allowing 2 units to be able to upgrade into each other. Here's the solution I see (ignoring the 'what if' question of other techs needing to be un-/re-researched upon capture):
  • The first 3 upgrades to the city stay as normal upgrades: great hall, town hall, city hall
  • Capital is treated as a building that the Base building (which encompasses all 4 of <none>/great/town/city) upgrades into, but is otherwise identical
  • To hide this from the command card of the Base building, you can disable training of it for the owning player (and re-enable when city hall is completed) or visually disable it by using some dummy units as requirements
  • Capital has the Base building in its 'upgrades to' field so it can be downgraded
  • Base building has a button position of 0,-11 so it's hidden on the Capital command card (I believe this would work just like hiding a spell would) and a hotkey the player is unlikely to press
  • Upon completed upgrade to Capital, store that unit in a variable
  • If there was a previous capital, do these things:
    • Give the player the appropriate gold/lumber to build a City Hall (this can probably be 0 because a player would never manually build a Base building anyway)
    • Cancel all current research at the Capital or wait until all research is done (might be possible to rebuild the research queue with a resource IcemanBo made)
    • Order the Capital to upgrade to a base building (depending on which race it is, this will be a different unit)
    • Immediately set the Capital's upgrade percentage to 100%, which instantly completes the downgrade
    • Store the new Capital in the variable
 
Last edited:
Level 9
Joined
Jul 30, 2018
Messages
445
I delved further, and it turns out the 'research and end of turn' thing is actually a problem.

I see. Thank you for pointing out those cases. I think the problem is that A New Day trigger is not actually ran if the button is not pressed. I have to dig into that.

The issue is that upgrades cannot be unresearched; wc3 simply doesn't support it.

Oh, right! So it just looks like it lowers the research level (by showing the Capital's button as the next level of the research), but no stats are actually lowered. I guess I have to find another way to limit capitals to one.
 
Level 1
Joined
Dec 4, 2019
Messages
7
Pyro your thorough testing and explanation is very good. Even having never played his map, your suggestion would be extremely easy to follow if i wanted to make something similar myself from scratch.
 
Status
Not open for further replies.
Top