Forums > Javascript

the_mods has no properties

February 24, 2010 | 12:56 pm

hi,
strange error, i can’t see why it happens. the_mods is the modifiers object, scripting name "modifiers". when i first open the patch, it comes with the error in the title, and the [modifiers] object in the patch doesn’t recognise the cmd key (understandably). when i save the js, it’s ok. so i guess the js isn’t initialising the max object properly (because loading the patch with command pressed shows the loadedOK message). i don’t understand as 10 minutes ago it was working ok. can anyone offer any assistance with my understanding?
cheers,,

– Pasted Max Patch, click to expand. –

//js script slider.control.js
//inlets and outlets
inlets = 3;
outlets = 3;

var the_slider = this.patcher.getnamed("theslider");
var the_mods = this.patcher.getnamed("modifiers");
the_mods.message("interval", 10);

function msg_float(arg)
{
}


February 24, 2010 | 10:19 pm

taking a guess at this… the code in question is in the block that gets called when your js object is initialized. if it gets initialized before the modifiers object (or the theslider object), your calls to patcher.getnamed will fail (i.e. return undefined), resulting in the error above when you call the_mods.message.

try putting all 3 lines in a loadbang function.


February 24, 2010 | 10:31 pm

hi brian,
thanks for your response. i just deleted and re-instantiated the modifiers object, and the problem went away.
but i’ll put it in a loadbang function just in case. just curious, would you say it’s good practice to put code like this in a loadbang function? or is it more a thing peculiar to this situation?
cheers,,


February 24, 2010 | 10:41 pm

You can’t access to the patcher structure before the patch and every object is properly instantiated, so using the loadbang method is the way to go.


February 24, 2010 | 11:01 pm

cool, thanks!


February 25, 2010 | 12:02 am

ok, so now the opposites happening. when i open the the patch, everything works as i want it, but after saving, the "the_sliders" object throws the "has no properties" error, after saving the js (cmd-move the range to the end). tried re-instantiating the rslider to no avail. so moved the this.patcher.getnamed method outside the loadbang, works ok after saving. why does it happen for some objects and not others? is it an order of execution thing (i.e. right to left)? then why does the rslider object reference die after saving the patch after it’s already successfully instantiated? (the below patch works, btw (at least it should). but move the_slider = this.patcher.getnamed("theslider"); to inside lodabang() and it demonstrates the issues above).
cheers,,

– Pasted Max Patch, click to expand. –

//inlets and outlets
inlets = 3;
outlets = 3;

var range_start;
var range_end;
var view_max;
var view_start = 0;
var display_size;
var adjusted_min;
var adjusted_max;
var cmd_bool;
var the_slider;
var the_mods;

the_slider = this.patcher.getnamed("theslider");

function loadbang()
{
the_mods = this.patcher.getnamed("modifiers");
the_mods.message("interval", 10);
}

function msg_float(arg)
{
if(inlet==0) {
range_start = arg;
outlet(0, range_start);
} else if(inlet == 1) {
range_end = arg;
//post("range end: ", range_end, "n");
}

display_size = range_end – range_start;
outlet(1, display_size);

if(cmd_bool) {

//post("cmd-pressedn");
//post("view max: ", view_max, "n");

if(range_end == view_max) {
adjusted_min = view_max – display_size;
the_slider.message("set", adjusted_min, view_max);
//post("range end: ", view_max, "n");
//post("range start: ", adjusted_min, "n");
}
}
}

function set_view_max(buffer_size)
{
view_max = buffer_size;

}

function cmd_pressed(arg)
{

arg==1 ? cmd_bool=1 : cmd_bool=0;
}


February 25, 2010 | 1:22 am

It looks like you’re trying to constrain the range to the minimum and maximum when the modifier key is held down. If I’m right then have a look at this code which should do the job. If not then I got a bit lost reading your code and it might be worth saying exactly what you’re trying to achieve.

lh


// lh.rsliderconst.js

var low = jsarguments[1] || 0;
var high = jsarguments[2] || 127;

function list(a,b) {
    if (a==low) {
        outlet(0,"set",low,range);
    } else if (b==high) {
        outlet(0,"set",high-range,high);
    } else {
        range = b-a;
    }
}

function setminmax(x,y) {
    low = x;
    high = y;
}

function anything() {
    post("lh.rsliderconst.js: doesn't understand ""+messagename+""n");
}

autowatch = 1;

// EOF

February 25, 2010 | 1:43 am

high luke,
thats kind of what i’m trying. basically i got annoyed when using waveview~ and having the view zoom in when i adjusted the view start past (buffer_size – display_size), and stay zoomed when readjusting display_start. the code above works how i want, i.e. the display_size (i.e. range size) stays the same when the buffer_size (max) is reached. however there’s some problems. for starters, when hitting repeatedly the end i can make the range size increase, due to the fact that range_min doesn’t stay constant (moves back by 0.01 each time). also, when at the buffer_start the current rage_size doesn’t stay the same like at the other end, it decreases a bit each time. i hacked around this by only using the display size as it was before entering into a lower limit. it doesn’t work completely but at least it stops the window shrinking a bit. i’ll post the code again below, updated with my hack for the lower limit,,
cheers,,

by the way, how do you get your code formatted nicely like that?
//inlets and outlets
inlets = 3;
outlets = 3;

var range_start;
var range_end;
var view_max;
var view_start = 0;
var display_size;
var adjusted_min;
var adjusted_max;
var cmd_bool;
var the_slider;
var the_mods;
var current_disp;
var at_the_start=0;

the_slider = this.patcher.getnamed("theslider");

function loadbang()
{
the_mods = this.patcher.getnamed("modifiers");
the_mods.message("interval", 10);
}

function msg_float(arg)
{
if(inlet==0) {
range_start = arg;
outlet(0, range_start);
} else if(inlet == 1) {
range_end = arg;
//post("range end: ", range_end, "n");
}

if(!at_the_start) {
display_size = range_end – range_start;
}

outlet(1, display_size);

if(cmd_bool) {
current_disp = display_size;
//post("cmd-pressedn");
//post("view max: ", view_max, "n");

if(range_end == view_max) {
adjusted_min = view_max – current_disp;
the_slider.message("set", adjusted_min, view_max);
//post("range end: ", view_max, "n");
//post("range start: ", adjusted_min, "n");
}

if(range_start < 0.002) {
at_the_start = 1;
adjusted_max = view_start + current_disp;
post("at the start: ", adjusted_max, "n");
the_slider.message("set", range_start + 0.001, adjusted_max);
} else {
at_the_start = 0;
}
}
}

function set_view_max(buffer_size)
{
view_max = buffer_size;

}

function cmd_pressed(arg)
{

arg==1 ? cmd_bool=1 : cmd_bool=0;
}


February 25, 2010 | 1:58 am

Change the final else block to include the line:

outlet(0,"set",a,b);

at the end and then use a [route set] after the [js] object and use these values instead of the ones directly from the [rslider] and that should take care of everything.

lh


February 25, 2010 | 2:06 am

i’m a bit confused, where should i send the values after [route]? i put them into the js object and got the stack overflow message. putting them into the rslider crashed max instantly.

if(range_start < 0.002) {
at_the_start = 1;
adjusted_max = view_start + current_disp;
post("at the start: ", adjusted_max, "n");
the_slider.message("set", range_start + 0.001, adjusted_max);
outlet(1, "set", range_start, adjusted_max);
} else {
at_the_start = 0;
}


February 25, 2010 | 2:19 am

If you link the outlet of my [js] directly into the [rslider] then also [route set] the outlet you can use this seperately to show what the current values are. Here’s the help file for the code I posted earlier with the mod.

To keep the formatting when pasting javascript you can use the "pre" and "code" html tags, the ones that are automatically included when you paste compressed max 5 code to the forum.

lh

– Pasted Max Patch, click to expand. –

February 25, 2010 | 2:31 am

hm, cheers. i still get a stack overflow when routing from my js to the rslider. but i’ll look at it after some lunch.
cheers again for the help,,


February 25, 2010 | 2:40 am

Perhaps look at using patch cords to make the connections, then you could use [defer] or [deferlow] if you really have to. However I think it should still be possible to do this all from inside your javascript. Are you just trying to constrain the [rslider] to stay within the "minmax" range? If so then post the code and patch you have now and I’ll take a look in the morning if I have time.

lh


February 25, 2010 | 1:42 pm

hi luke,
thanks a lot for your help. probably be a few days now as i have school work again,
cheers,,


February 28, 2010 | 12:18 am

hi luke,
thanks for all your help. seems as i was updating the range regardless of where it was was causing screwy things to happen. i still get screwy errors with instantiating the rslider reference inside the loadbang and not being able to call other methods on it, but thats ok i can work around it. below is my updated js borrowed heavily from yours, with provisions to zoom in/out when at either end..
cheers again,,

//inlets and outlets
inlets = 3;
outlets = 3;

var range_start;
var range_end;
var view_max;
var view_start = 0;
var display_size;
var cmd_bool;
var the_slider;
var the_mods;
var key_sim

the_slider = this.patcher.getnamed("theslider");
key_sim = this.patcher.getnamed("keysim"); 

function loadbang()
{
    the_mods = this.patcher.getnamed("modifiers");
    the_slider = this.patcher.getnamed("theslider");
    the_slider.message("listmode", 1)
    the_mods.message("interval", 10);
}

function list(min, max)
{
    range_start = min;
    range_end = max;

    post("disp: ", display_size, "n")
    if (min==view_start) {
        if(cmd_bool) {
            the_slider.message("set", min, display_size);
        }
    } else if (max==view_max) {
        if(cmd_bool) {
            the_slider.message("set", view_max-display_size, view_max);
        }
    } else {
        display_size = max - min;
    }
}

function msg_float(arg)
{

}

function set_view_max(buffer_size)
{
    view_max = buffer_size;
}

function cmd_pressed(arg)
{

    arg==1 ? cmd_bool=1 : cmd_bool=0;
}

function fix_range(fix)
{
    cmd_bool=fix;
    if(fix) {
        key_sim.message("keydown", 55);
    } else {
        cmd_bool=0;
        key_sim.message("keyup", 55);
    }
}

February 28, 2010 | 12:27 am

and a maxpat to go with it..
edit: updated with a range_fix: fix the range without having to hold command,
you’ll need aka.keyboard
that’s all,,

– Pasted Max Patch, click to expand. –

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