|
Corel Click &
Create
Tip 13 - About the Mod key
The Mod key is a mathematical operator located in the
Expression Evaluator that can be used in expressions to perform a remainder operation. Mod is
used to divide the first number by the second and calculate the remainder. For example, 7 mod.3
is calculated as follows: Click & Create divides 7 by 3. Since the result is not a whole
number, the result is two with one left over. Therefore, 7 mod 3 equals 1.
Mod displays the fractional part of a division. There are
many uses for the Mod function in your Click & Create applications.
The following example can be used to generate the suit
and the value of the cards in a card game. This procedure may be confusing if you're unfamiliar
with Click & Create Expressions.
Here's how to generate the suit and the value of a deck of
cards:
- Create a series of fifty-two card objects to represent your
deck. These objects need to have a different animation for each of the possible face values. To do
this, assign each value to a different direction.
- You also need a different set of animations for the four
suites, Clubs, Spades, Diamonds, and Hearts. Enter each sequence as separate animation types.
- Now, give each card a unique identification number
from 0 to 51, using a Spread a value of 0 in card(A) action.
In this game, the suit of the card can be worked out using
the following process:
- Number the cards in ascending order. You can do this by
subtracting the value from fifty-two. Use the function Alterable Value of card(A). This sets the
first card to one, the second to two, and the last card to fifty two.
- Convert the card number into the suit number by
dividing the number by 4. Use the function: [52 - Alterable Value of card(A)]/4. This would
generate a value from 0 to 3, where 0=Clubs, 1=Spades, 2=Diamonds, and 3=Hearts.
- Now, use this value to display the appropriate animation
type for the card. Use the Change Animation action and enter the calculation in the Expression
Evaluator.
- To obtain a face value between 1 and 13, take the
previous range, and get the remainder after a division by 13. You can get the remainder using a
function called "Mod". [52 - Alterable Value of Card(A)] Mod 13. This would give a
number from 0 to 12. We could add one to this to get the required range.
- Our final expression would be [(52 - Alterable Value of
Card[A]) Mod 13+1].
- Use the Change Animation Direction action to choose
the correct animation for the selected card.
![[Click here for
previous tip]](/deadend) ![[Click here
for next tip]](/deadend)
|
Click &
Create
|