General code question from a noob
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins
3 posts
• Page 1 of 1
General code question from a noob
by moomarc » 20 Jan 2012, 22:16
When I originally copied Persist to add Undying to Forge I came across something in CombatUtil that I wonder if anyone can clarify for me (I'm trying to learn bit of coding by following patterns so notice things like this). The relevant bits of code are these (from CanDestroyBlocker/Attacker blocks):
if (((attacker.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(attacker) && !withoutAbilities)) && !(defender
.hasKeyword("Wither") || defender.hasKeyword("Infect")))
|| (attacker.hasKeyword("Persist") && !attacker.canHaveCountersPlacedOnIt(Counters.M1M1)
&& attacker.getCounters(Counters.M1M1) == 0)
|| (attacker.hasKeyword("Undying") && !attacker.canHaveCountersPlacedOnIt(Counters.P1P1)
&& attacker.getCounters(Counters.P1P1) == 0)) {
if (((defender.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(defender) && !withoutAbilities)) && !(attacker
.hasKeyword("Wither") || attacker.hasKeyword("Infect")))
|| (defender.hasKeyword("Persist") && !defender.canHaveCountersPlacedOnIt(Counters.M1M1))
&& defender.getCounters(Counters.M1M1) == 0
|| (defender.hasKeyword("Undying") && !defender.canHaveCountersPlacedOnIt(Counters.P1P1))
&& defender.getCounters(Counters.P1P1) == 0) {
I'm just wondering why the two blocks are bracketed differently and if it makes any difference. Not important really, just interested to find out. I identified the differences in red/green (the first one looks more right to me because it encapsulates the whole condition, but I don't know).
if (((attacker.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(attacker) && !withoutAbilities)) && !(defender
.hasKeyword("Wither") || defender.hasKeyword("Infect")))
|| (attacker.hasKeyword("Persist") && !attacker.canHaveCountersPlacedOnIt(Counters.M1M1)
&& attacker.getCounters(Counters.M1M1) == 0)
|| (attacker.hasKeyword("Undying") && !attacker.canHaveCountersPlacedOnIt(Counters.P1P1)
&& attacker.getCounters(Counters.P1P1) == 0)) {
if (((defender.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(defender) && !withoutAbilities)) && !(attacker
.hasKeyword("Wither") || attacker.hasKeyword("Infect")))
|| (defender.hasKeyword("Persist") && !defender.canHaveCountersPlacedOnIt(Counters.M1M1))
&& defender.getCounters(Counters.M1M1) == 0
|| (defender.hasKeyword("Undying") && !defender.canHaveCountersPlacedOnIt(Counters.P1P1))
&& defender.getCounters(Counters.P1P1) == 0) {
I'm just wondering why the two blocks are bracketed differently and if it makes any difference. Not important really, just interested to find out. I identified the differences in red/green (the first one looks more right to me because it encapsulates the whole condition, but I don't know).
-Marc
-

moomarc - Pixel Commander
- Posts: 2091
- Joined: 04 Jun 2010, 15:22
- Location: Johannesburg, South Africa
- Has thanked: 371 times
- Been thanked: 372 times
Re: General code question from a noob
by Sloth » 21 Jan 2012, 08:13
You are right, the first one is correct the second one needs to be fixed.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: General code question from a noob
by moomarc » 21 Jan 2012, 08:55
Glad I finally asked about it then. I've committed the fix.
-Marc
-

moomarc - Pixel Commander
- Posts: 2091
- Joined: 04 Jun 2010, 15:22
- Location: Johannesburg, South Africa
- Has thanked: 371 times
- Been thanked: 372 times
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 13 guests