Forums > MaxMSP

how to set a threshold

February 25, 2010 | 8:15 am

I am using [if] to set a threshold. I have randomly generated number from 0-100, if the number is smaller than 80 (as long as the number is smaller than 80), I would like the counter to count. If not, do not count. So if I have generated 60, 45, 75, 20, in a roll, the counter should only count once. But I could not figure out how to do this. I put a toggle after [if], the toggle sends a bang to the [counter] so everytime the number is smaller than 80, the counter counts. Any suggestions on who to fix this?

Below is my code. Thank you all

{
"patcher" : {
"fileversion" : 1,
"rect" : [ 25.0, 69.0, 640.0, 506.0 ],
"bglocked" : 0,
"defrect" : [ 25.0, 69.0, 640.0, 506.0 ],
"openrect" : [ 0.0, 0.0, 0.0, 0.0 ],
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 0,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 0,
"toolbarvisible" : 1,
"boxanimatetime" : 200,
"imprint" : 0,
"boxes" : [ {
"box" : {
"maxclass" : "number",
"numoutlets" : 2,
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 165.0, 400.0, 50.0, 20.0 ],
"fontname" : "Arial",
"id" : "obj-8",
"numinlets" : 1,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "counter 0 0 100",
"numoutlets" : 4,
"outlettype" : [ "int", "", "", "int" ],
"patching_rect" : [ 175.0, 349.0, 94.0, 20.0 ],
"fontname" : "Arial",
"id" : "obj-7",
"numinlets" : 5,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "toggle",
"numoutlets" : 1,
"outlettype" : [ "int" ],
"patching_rect" : [ 193.0, 308.0, 20.0, 20.0 ],
"id" : "obj-6",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "sel 1",
"numoutlets" : 2,
"outlettype" : [ "bang", "" ],
"patching_rect" : [ 197.0, 274.0, 36.0, 20.0 ],
"fontname" : "Arial",
"id" : "obj-5",
"numinlets" : 2,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "number",
"numoutlets" : 2,
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 234.0, 199.0, 50.0, 20.0 ],
"fontname" : "Arial",
"id" : "obj-4",
"numinlets" : 1,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "if $i1 < 80 then 1 else 0",
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 197.0, 237.0, 135.0, 20.0 ],
"fontname" : "Arial",
"id" : "obj-3",
"numinlets" : 1,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "random 100",
"numoutlets" : 1,
"outlettype" : [ "int" ],
"patching_rect" : [ 224.0, 164.0, 75.0, 20.0 ],
"fontname" : "Arial",
"id" : "obj-2",
"numinlets" : 2,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "button",
"numoutlets" : 1,
"outlettype" : [ "bang" ],
"patching_rect" : [ 250.0, 104.0, 20.0, 20.0 ],
"id" : "obj-1",
"numinlets" : 1
}

}
],
"lines" : [ {
"patchline" : {
"source" : [ "obj-7", 0 ],
"destination" : [ "obj-8", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-6", 0 ],
"destination" : [ "obj-7", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-5", 0 ],
"destination" : [ "obj-6", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-3", 0 ],
"destination" : [ "obj-5", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-2", 0 ],
"destination" : [ "obj-4", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-2", 0 ],
"destination" : [ "obj-3", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-1", 0 ],
"destination" : [ "obj-2", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
]
}

}



Ch
February 25, 2010 | 8:42 am
– Pasted Max Patch, click to expand. –

February 25, 2010 | 6:32 pm

Thanks for the response Ch. But the problem does not seem to be solved. If I got a few numbers smaller than 80 in a roll. For example, I got 56, 34, 10, 23, in a roll, the counter counts each time when the number is smaller 80. I want the counter only count once until I reach a number bigger than 80.


February 25, 2010 | 7:21 pm

instead using [if], maybe I should use some other objects, which can find the maximum and minimum among a few input numbers? I do not know which object I should use.



MIB
February 25, 2010 | 7:28 pm

use [onebang] to only allow the first bang to come through. then if the number goes above 80 reset onebang…

– Pasted Max Patch, click to expand. –

February 25, 2010 | 7:33 pm
– Pasted Max Patch, click to expand. –

February 25, 2010 | 7:37 pm

Wow, awesome. Thank you both MIB and Chris.


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