image:9_020_Codepoint.png[alt=""]
Step 3: Modifying an Object Property
If you haven’t been following this tutorial from the beginning, open project file Dart Measure.mg4.
Delete a Code Point Result
Our third way of eliminating the dart uses a Code Point rather than an If Point. First we need to delete the If result again.
Highlight |
if 2 > Dart Depth |
Highlight |
Result "D3" |
Click |
Delete X (right side) |
Close the form |
This time, we’re going to create two objects: the original object with the dart, and an alternate version with no dart. Depending on whether we want the dart, our Code Point will hide one object and show the other.
Draw an object without a dart.
Name |
No Dart |
Closed |
Checked |
Left-click |
Start |
Left-click |
1 |
Left-click |
2 |
Left-click |
3 |
Click |
OK |
Your new object will be hard to see because object Dart obscures it—that’s OK:
From the top-level menu, bring up the If Point form again.
Highlight |
if 2 > Dart Depth |
Click |
Advanced Results |
In the IfAdvancedChoice form,
Check |
Add Code Point |
Click |
OK |
The CodePoint form is an advanced MacroGen feature for programmers. This tutorial will only touch on its use. We can select the type of entity we want to modify (object) from the Type pulldown, select the object from the List pulldown, and select an object property we wish to change from the Accel pulldown. The big text area at the bottom of the form is for entering macro code directly—that is beyond the scope of this tutorial.
"Hide Dart" is the object we want to modify.
Name |
Hide Dart |
Type |
Object |
The List pulldown lists the objects we’ve defined in the macro. The extra characters are part of the internal code MacroGen uses. Look for the name of the object we’re interested in, which is "Dart". Go to the "List" pull-down:
List |
@Object[Dart] |
Accel |
Select Hide |
This tells it we want to modify the hide property of the dart object
Click |
Paste Button |
This types in the code @Object%5BDart%5D.Hide
Change the text so it looks like: @Object[Dart].Hide = 1;
which is a statement in the Patternmaker macro language. (For the Hide property, 1 means hide it; 0 means show it.)
Click |
Ok |
In doing this we’ve told the program to hide the Dart object if 2 > dartdepth
Now to hide the other object. The "No dart" object is hidden when our condition is false—much like the "Else" branch of an IF statement in many programming languages. To program this branch, check the False radio button on the If form.
Check |
False |
Click |
Advanced Result |
Check |
Add Code Point |
Click |
OK |
Name |
Hide No Dart |
Under Type Select |
Object |
Under List Select |
@Object[No Dart |
Under Accel Select |
Hide |
Click |
Insert |
Change the code to look like
@Object[No Dart].Hide = 1;
Click |
OK |
There you have it: if the condition "2 > Dart Depth" is true, then the Code Point hides object "Dart". If the condition is false, it hides object "No Dart". To check your work, change the value of the measure Width from 10 to 6 and back to verify that the If block works. You should see the dart appear and disappear as either object "Dart" or "No Dart" is displayed.
Your project should now be the same as the one in project file Hide Object.mg4.