HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Trigger problem...

01-16-2005, 09:43 PM#1
Zarniwoop
Aye. So I'm doin' this wee map here wich, hopefully, in the end will support players "trading" with eachothers, by sending ships and caravans to eachothers' markets and, at their return, receive some money.

Now, this will all get very elongated, with the triggers and all, so I'll explain the problem right away.
It works the way that you've got these caravan-units, and they travel between two regions. Depending on the distance between the two, the units' Custom value is changed to that. And once they get into their "home region" the Custom value is converted to gold for the player.
Everything works perfectly.
However, I want to be able to move the regions, simply by building a new market, to where you move the region. So, teorethically, the "trading" would simply cease to work at the old place once a new market is built and the region is moved.
Strangely, though the region IS moved, the trading still works at the old place, but not at all from the new location.

Sigh. If you have ideas, what's wrong with my triggers or other ways to do it, please tell!

Righty. Now I'll display three triggers, the variables used are:

distance - integer - distance between a "trade unit" and it's players market(variables below)
market1 - unit - player 1's market
market2 - unit - player 2's market

And the two regions are:
Market1 <gen> - region surrounding player 1's market
Market2 <gen> - region surrounding player 2's market

And a last note; all trade-units have been classified as Sappers!

And the three triggers;

Trigger #1 (EnterMarket1)- Giving gold or editing unit's custom values when they enter Market1 <gen>
Events
- A unit enters Market1 <gen>
Conditions
- ((Triggering unit) is A sapper) Equal to True
Actions

- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-> If - Conditions
- - (Owner of (Triggering unit)) Equal to Player 1 (Red)
-> Then - Actions
- - Player - Add (Custom value of (Triggering unit)) to Player 1 (red) Current gold
- - Unit - Set the custom value of (Triggering unit) to 0
-> Else - Actions
- - Do nothing

- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-> If - Conditions
- - (Owner of (Triggering unit)) Equal to Player 2 (Blue)
-> Then - Actions
- - Set Distance = (Integer((Distance between Position of (Triggering unit)) and (Position of market2)))*
- - Set Distance = (Distance / 500)
- - Unit - Set the custom value of (Triggering unit) to Distance
-> Else - Actions
- - Do nothing

*Now when I think of it, that variable is rather unneccessary, can simply take "center of region" instead, but it doesn't matter as it clearly isn't that wich is the problem here...

What this means is that if a unit classified as a Sapper (or Suicidal) enters the region Market1 <gen>, it checks if it's owned by...
... Player 1, in wich case it simply adds the custom value of the unit to Player 1's gold.
... Player 2 (and all else), in wich case it calculates the distance between the triggering unit and the Market of player2, divides it with 500, and makes that the custom value for the unit.

Trigger #2 (EnterMarket2)- Same as the previous, only for player 2's market.
Events
- A unit enters Market2 <gen>
Conditions
- ((Triggering unit) is A sapper) Equal to True
Actions

- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-> If - Conditions
- - (Owner of (Triggering unit)) Equal to Player 1 (Red)
-> Then - Actions
- - Set Distance = (Integer((Distance between Position of (Triggering unit)) and (Position of market1)))
- - Set Distance = (Distance / 500)
- - Unit - Set the custom value of (Triggering unit) to Distance
-> Else - Actions
- - Do nothing

- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-> If - Conditions
- - (Owner of (Triggering unit)) Equal to Player 2 (Blue)
-> Then - Actions
- - Player - Add (Custom value of (Triggering unit)) to Player 2 (red) Current gold
- - Unit - Set the custom value of (Triggering unit) to 0
-> Else - Actions
- - Do nothing

Now, if you simply leave it at that and run the map, with two regions with markets in them, and a couple of units of sapper-type, everything runs perfectly.

However, the point of the whole is that when you build a new Market, it will become the new "tradecenter" and the trading will go trough it, instead.
Simple enough, you think.

Trigger #3 (BuildMarket1)- Build a market and move regions...
Events
- Unit - A unit Finishes construction
Conditions
- (Unit-type of (Triggering unit)) Equal to Marketplace
Actions

- Region - Center Market1 <gen> on (Position of (Triggering unit)
- Set market1 = (Constructed structure)

Yah. All regions and variables moved over to the new Market.

But now comes the mystifying. Everything has worked so far, flawlessly.
However - for some reason, the trading still goes trough the old marketplace, and nothing happens when they go to the new market.
Oh! - you say. The region hasn't moved, for some reason.
Simple enough, I add a small unit spawn every two seconds and run it.
The region has moved! - the unit spawn follows it, and the new marketplace. But still, the trading goes trough the same old tradingplace!
Maybe there's something with the market variable?
Check, check, kill market1 after X seconds. Kills the new marketplace. Trading STILL goes trough the old marketplace.

Now for the love of god! Does anyone understand this?!

Well well. Help's appreciated, very, very, veeery much. Wether it is pointing out what's wrong with my triggers or perhaps other ways of doing it, please tell me!
01-17-2005, 04:18 PM#2
Zarniwoop
- bump -

I'd really like anyone who might know what the heck's happening here, to answer, since it, to me, seems like... the weirdest thing ever.
01-17-2005, 04:55 PM#3
GosuSheep
Trigger #3 (BuildMarket1)- Build a market and move regions...
Events
- Unit - A unit Finishes construction
Conditions
- (Unit-type of (Triggering unit)) Equal to Marketplace
Actions

- Region - Center Market1 <gen> on (Position of (Triggering unit)
- Set market1 = (Constructed structure)


well. whyd u change it from triggering unit to, constructed structure... couldnt u leave it as triggering unit? i think thats whats going on
01-17-2005, 05:59 PM#4
aaero
I've had a string of bad luck lately trying to solve problems, but I'll offer another suggestion though I'm not completely sure.

Many, if not all, events are pre-compiled. Basically, this means that when the map is saved, the events are already decided - changes to those events won't be applicable. This is semi-hard to explain...

Basically, the coordinates of the region are added to the event when the map is saved. Moving the region won't move those coordinates - the region isn't in the event anymore, it's coordinates are.

I'm still trying to think of a good solution, but maybe you'll think of one now that you know the cause :) (assuming I'm right).
01-17-2005, 07:23 PM#5
oNdizZ
you don't have to order a unit to a region. Or, hmm, what you actually are doing is to order the unit to a point, and that would be another idea? ignore the regions and use point variables instead. and if you had it like when a unit enters that region use "gets in range of.." instead.
And if you dont know this: you can't add unit vars in events unless you add the event with a specific action called something like: Trigger - Add Event to "that" trigger.

what i've tried to help with here is that becouse of what aeero said that you can't just move the regions (the cordinates still the same) but you can move the points without any problems, i see some memory leaks though, but, if you arent sure about them, don't change em before you know what memeory leaks are and know how to fix them. (only thing i can handle when it comes to memory leaks are so far: points, unit groups, player groups...)
But you will probebly find any good Jass triggerer who can help you ;)

good luck
01-18-2005, 05:12 AM#6
Zarniwoop
Waily, waily. Point variables, eh? Well thanks for the help, lads, I'll try to do it.
Memory leaks, you say? Huh. I better do some research on that area lest I'll appear outragioushly noobish...

GosuSheep, good question, although that's not the problem, I'm sure. Thanks anyway.


Although, as it turns out, it doesn't help. I've tried adding the events to the triggers; A unit comes within range of (markets), and even creating a region, centered at the market (of width&height 750), making that a variable, and then moving the variable around, if you understand me,
- but nothing works. Sadly. Sigh.