It is currently 29 Oct 2025, 12:27
   
Text Size

General code question from a noob

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins

General code question from a noob

Postby 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).
-Marc
User avatar
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

Postby Sloth » 21 Jan 2012, 08:13

You are right, the first one is correct the second one needs to be fixed.
User avatar
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

Postby moomarc » 21 Jan 2012, 08:55

Glad I finally asked about it then. I've committed the fix.
-Marc
User avatar
moomarc
Pixel Commander
 
Posts: 2091
Joined: 04 Jun 2010, 15:22
Location: Johannesburg, South Africa
Has thanked: 371 times
Been thanked: 372 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 13 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 13 users online :: 0 registered, 0 hidden and 13 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 13 guests

Login Form