add x amount to a value

Jul 26 2013 | 6:36 pm
Hi,
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?
Best,
ana

• Jul 26 2013 | 7:16 pm
Hi Ana,
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!)
• Jul 26 2013 | 8:35 pm
Hi,
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.
ana
• Jul 26 2013 | 8:37 pm
ah, I figured it out:
• Jul 26 2013 | 8:39 pm
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.")