Login    Forum    Search    FAQ

Board index » Scenarios & Scripting




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Example: blocking a certain card
 Post Posted: Tue Mar 23, 2010 9:03 pm 
Offline

Joined: Tue Jan 08, 2008 2:07 am
Posts: 1045
Take out all the Soul Plagues from a player's deck.

Code:
void beforeStart()
{
   Player player=getHumanPlayer(0);
   
   ds=player.deckSize();
   for(int n=0; n<ds; n++)
   {
      if( player.getDeckCard(n).getName()=="Soul Plague")
      {
         player.removeDeckCard(n);
         n--;
      }
   }   
}


Top 
 Profile  
 
 Post subject: Re: Example: blocking a certain card
 Post Posted: Tue Mar 23, 2010 10:52 pm 
Offline

Joined: Fri Nov 13, 2009 8:26 am
Posts: 139
it is both exciting and terrifying that this is the API that has been exposed to players. anyway, if I am interpreting the code correctly, I think it will break (unless there is some embedded exception handling for accessing a card with an index greater than the deck size).

in general, try to avoid changing the loop iterator (n, in this case) outside the loop definition. e.g.,

Code:
void beforeStart()
{
  Player p = getHumanPlayer(0);
 
  for ( int n = p.deckSize()-1; n >= 0; n-- )
  {
    if ( p.getDeckCard(n).getName() == "Soul Plague" )
    {
      p.removeDeckCard(n);
    }
  }   
}


Top 
 Profile  
 
 Post subject: Re: Example: blocking a certain card
 Post Posted: Wed Mar 24, 2010 2:10 am 
Offline

Joined: Tue Jan 08, 2008 2:07 am
Posts: 1045
Yeah it wont break. It will just return an invalid card at the end which will return "" on getName.
But your version is probably cleaner.

> it is both exciting and terrifying that this is the API that has been exposed to players.
Yeah I wish I had done this a looooong time ago.


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 3 posts ] 

Board index » Scenarios & Scripting


Who is online

Users browsing this forum: No registered users and 4 guests

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: