add x amount to a value
This may seem extremely simple, but I have been boxing around with max objects for a while now. How do I add or subtract x amount to a number that is already there?
Have a look at the [+] and [-] objects. You can either type in an argument so that the object will always add or subtract the same amount, for example [+ 10]. Or you can send a number to the right inlet and make it variable. Have a look at Max Tutorial 6 (Max5) for how to perform basic maths operations. Remember, if you want to work with floating point numbers (decimals) then you need to use [+ 0.] (notice the decimal point after zero) as these objects otherwise assume you will only ever want to use integers.
If you’re still stuck after reading the first few tutorials, post your patch here so we can talk you through things step by step. (To post your patch here select everything in the patcher window then select "Copy Compressed" from the Max edit menu and simply paste into your reply!)
yes, I don’t think i formulated the question right. I need to add 30 to a value that changes all the time, and still avoid stack overflow. I try to ise the int object, but I can’t seem to make it work.
ah, I figured it out:
----------begin_max5_patcher---------- 588.3oc0WF0aaBCDG+Y3SAxutzJ.aLg9Vk1K6yvzTkI305JhIxX5xVU+tO6y PZRVJwMhj18Bn6vb9+86L9LOGFfJaVyaQQ2D88nffmCCB.WVGA81Ankr0KpY svvPxtkkbEZl6QFqlNcMWCOLs26Oaj5Vwe3VeIoWG26dESu3Ag796T7EZ2bh IwlGGQH41aYfQp4ZzO5eGQELqMkOdEIEsIPJ1RtlqtiKYk0v7LLIN4n+8Jta FPBoFMKBUxj2i1DVqBklX.A+VkfUuUFIjCITh02Kgg1Ky7EP7eYT6P3z70Pp hzSMxRw1azrqyFAYXzagEKS9H4wWNLORNUdfKJ.dPGkGDzXKSdu3Hc5vgXpw QdFrJoXTbj8YEG5nRipmpOYHXJvjTe1kg9lLA1BY1owljokMWMcvYXAiWvI+ SCbr3nrSqajGFD3wAwFZ9U9BEm0xQGmPwvNtySGkPyOolTvtw+GRuuIOJ8F9 3yK5U7gRO3cQ0B49GIBRKq+cQZaSmZwfHF5uD8ZlUwa0BISKLXdqAg2YPOHp p3xsyuJQqMkArDevhq25A6idRur5I4X5IamA8u5YonZUioV2WjvEzsNCIAVl tmElBV34wardUDSW1U3CsoWNZO2G8je4zStOUex6r5apoli3fyJbmBzUnsVm iJbtODM6xQT5Yfnjb5Ejnzofn6mAjLWFj.R2cHXv5bjAY9jAjSbMgqkDa0pm 3p19XBRwzO+wFk0jNCLERmI7KCHE+Iwv3gl4HlxzYVaZK2ob8DWOmhBsyyKg +E.SqdZD -----------end_max5_patcher-----------
Key to avoiding stack overflow is to store the output from the addition/subtraction/etc. into the right inlet of the +/-/etc. You will need an intermediary "float" object or flonum since you can’t connect an object’s outlets directly to its inlets.
If you’re not familiar with hot and cold inlets, it’s worth going over the right-to-left ordering tutorials.
Alternatively, you can use the accum object. It deals with addition and multiplication. You may need to give it a floating-point argument to get it to floating-point math. (i.e. "accum 0.")