Forums > MaxMSP

add x amount to a value

July 26, 2013 | 11:36 am

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


July 26, 2013 | 12: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!)


July 26, 2013 | 1: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


July 26, 2013 | 1:37 pm

ah, I figured it out:

<code>

– Pasted Max Patch, click to expand. –

</code>


July 26, 2013 | 1: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.")


Viewing 5 posts - 1 through 5 (of 5 total)