I am trying to find out where I find subtract from counter when i right click on of my events in the event editor, i dont see it anywhere.
I am trying to find out where I find subtract from counter when i right click on of my events in the event editor, i dont see it anywhere.
Welcome to the forums.
Most objects do not provide actions for adding/subtracting values, alterable and global values are actually pretty unusual in that sense.
However, it is still quite easy to add or subtract. For a counter, try using the "Set Counter Value" action. When the Expression Editor opens, click "Retrieve Data. From an Object" and right-click the Counter you are setting. In the menu that opens, select the option that gets the Counter's value. Then you can subtract or add as you wish. For example, to subtract 5 you do:
Set Counter to value("My Counter") - 5
This literally sets the value of the counter to itself minus 5. Hope that helps.![]()
I dont understand what youre trying to tell me to do, by expression editor to you mean event editor? and i dont see anything that says " set counter value"
Actually, now that I have access to MMF, I see that the Counter object does in fact have actions for adding and subtracting.This is useful to know, however, so I will explain step-by-step.
Okay, let's suppose you have a Counter object in the frame called "My Counter". Its starting value is 100, and you want to subtract 5 from it when the user presses the space bar.
Go into the Event Editor and click New Condition. Select the Mouse/Keyboard object and create an "Upon Pressing Key" condition. Press space when the "Please press a key" window appears. You now have an event with 1 condition and no actions.
Add an action by right-clicking the Counter's box for that event, and select "Set Counter". Upon doing this, a window should appear asking for a value to set. This is called the Expression Editor, and will appear anytime MMF needs numeric or text input to complete an action. You are able to simply enter a number here, but it can also do much more powerful calculations.
Click "Retrieve data from an object". This button is to the right of the Expression Editor. An Object Selection Dialog should appear. Right-click the Counter in this window, and click the "Current value" menu item. Upon doing this, you will see the text value( "My Counter" ) appear in the input area.
This is an expression. When MMF reads value( "My Counter" ), it will substitute in the current value of your "My Counter" object (100, in this example). You can then perform math on this value in the Expression Editor. Try putting -5 at the end of the expression. The text in the Expression Editor should now read value( "My Counter" )-5.
Press OK to close the Expression Editor, then run your application. Everytime you press space, the Counter should decrease by 5. This is what actually happens:
- The first time you press space, value( "My Counter" ) is read as 100 (the Counter's value). The -5 causes the entire expression to be read as 100 - 5, or 95. Because this action, "Set Counter", is setting the actual contents of the Counter, it will now display 95 in the frame.
- The second time space is pressed, value( "My Counter" ) is read as 95 rather than 100. 5 is subtracted again, resulting in the Counter being set to 90.
I hope that helps you understand better.
Complete these steps to create an action that subtracts 5 from the Counter object when the alien collides with the shield.
1.**Click the View menu, and then click Event Editor.
2.**In the Collision between Alien and Shield row, in the Counter column, right-click the box, and then click Subtract from Counter.
3.**In the Subtract from Counter dialog box, under Enter expression to calculate, click the field, then delete the number that's there, and then type 5.
4.**Click OK.
5.**Test the game. Each time an alien collides with the shield, the Counter object gets smaller.*TIP: The shield won't be destroyed yet. You'll do that later.
This is what i am suppose to do?