cmdlist in javascript

Apr 25, 2007 at 3:52am

cmdlist in javascript

i found an earlier thread that cmdlist isn’t supported by a JS listener, but I’m wondering it’s possible to add commands to the list via JS. I have some commands formatted as such (for example):

var movex = .1;
var movey = .2;
hl_o.cmd_insert(0, “moveto”+ movex, movey+” 1″);
hl_o.cmd_insert(1,”glcolor 0 0 .7 1″);
hl_o.cmd_insert(2,”glbindtexture masktexture”);
hl_o.cmd_insert(3,”plane”+griddivx,griddivy);
hl_o.cmd_insert(4,”glbindtexture”);
hl_o.cmd_insert(5,”glcolor 1 1 1 1″);
render.erase_color=[0.7, 0.7, 0.7,1]
hl_o.draw();
render.drawswap();

which doesn’t generate any errors, but doesn’t do the same as:
var movex = .1;
var movey = .2;
hl_o.moveto(movex,movey,1);
hl_o.glcolor(0,0,.7,1);
hl_o.glbindtexture(“masktexture”);
hl_o.plane(griddivx,griddivy);
hl_o.glbindtexture();
hl_o.glcolor(1,1,1,1);
render.erase_color=[0.7, 0.7, 0.7,1]
hl_o.draw();
render.drawswap();

I can provide more example, if needed, but I’d like to check if it’s worth the time, of maybe cmd_insert just isn’t supported in JS.

Thanks,

Peter.

#31580
Apr 25, 2007 at 11:45am

On Apr 24, 2007, at 8:52 PM, pnyboer wrote:

>
> i found an earlier thread that cmdlist isn’t supported by a JS
> listener, but I’m wondering it’s possible to add commands to the
> list via JS. I have some commands formatted as such (for example):
>
> var movex = .1;
> var movey = .2;
> hl_o.cmd_insert(0, “moveto”+ movex, movey+” 1″);

Don’t make strings with the + operator. Use commas, as you do below.
This is a common mistake of Maxers thinking that JS strings are
parsed into atoms like a message box in Max. They are not.

> hl_o.moveto(movex,movey,1);

Let us know if that doesn’t work for you.

-Joshua

#102855
Apr 25, 2007 at 3:54pm

the reason I tried putting argurments into a symbol is that this:
hl_o.cmd_insert(0, moveto, movex, movey);
hl_o.cmd_insert(1,glcolor, 0, 0, .7, 1);
hl_o.cmd_insert(2,glbindtexture, masktexture);
hl_o.cmd_insert(3,plane,griddivx,griddivy);
hl_o.cmd_insert(4,glbindtexture);
hl_o.cmd_insert(5,glcolor, 1, 1, 1, 1);

results in an error:
? error: js: clipbank.js: Javascript ReferenceError: moveto is not defined, line 170

so I thought maybe I needed to pass the arguments as a symbol. Since that didn’t produce an error, I thought my chances had at least improved.

Thanks,

Peter.

#102856
Apr 25, 2007 at 3:58pm

if using cmdlist isn’t going to work, then I guess the real question is
how can I do a mouse-over highlight in gl.sketch without needing to clear and redraw the *entire context? I had hoped to use cmdlist to draw a rectangle highlight over a “grid cell” in a grid, then easily delete it and redraw it elsewhere, without having to upset the rest of the scene.

p

#102857
Apr 25, 2007 at 6:27pm

On Apr 25, 2007, at 8:54 AM, pnyboer wrote:

> the reason I tried putting argurments into a symbol is that this:
> hl_o.cmd_insert(0, moveto, movex, movey);
>
> results in an error:
> ? error: js: clipbank.js: Javascript ReferenceError: moveto is not
> defined, line 170
>
> so I thought maybe I needed to pass the arguments as a symbol.

A *symbol* must be passed as a JS string. In the above, moveto would
refer to a JS variable which doesn’t exist. In your attempt to use
the string concatenation + operator, you discovered that a long
string containing multiple atoms (i.e. symbols, integers, and/or
floats) as *text* is treated as a single symbol, not as a set of
atoms. i.e.:

hl_o.cmd_insert(0, “moveto “+movex, movey);

Corresponds to a max message containing *three* elements:

cmd_insert “moveto

For your case, it would be:

hl_o.cmd_insert(0, “moveto”, movex, movey);

Which corresponds to the max message containing *four* elements:

cmd_insert moveto

This is just like outlet calls and everything else in JS< ->Max, and
is a fundamental thing to understand. I hope that this distinction is
now clear.

-Joshua

#102858
Apr 25, 2007 at 6:40pm

ok, yeah, thanks for kicking my tiny brain into gear.
I actually do understand this, but I was convinced that I didn’t know what was happening.
Of course I got an error – since it wasn’t in quotes, JS thought the moveto was a variable, which of course hadn’t been defined, so it gave an error. duh.

P.

#102859
Apr 25, 2007 at 6:59pm

guess that should be

hl_o.cmd_insert(0, “moveto”, movex, movey);

Mattijs

Quote: pnyboer wrote on Wed, 25 April 2007 17:54
—————————————————-
> the reason I tried putting argurments into a symbol is that this:
> hl_o.cmd_insert(0, moveto, movex, movey);
> hl_o.cmd_insert(1,glcolor, 0, 0, .7, 1);
> hl_o.cmd_insert(2,glbindtexture, masktexture);
> hl_o.cmd_insert(3,plane,griddivx,griddivy);
> hl_o.cmd_insert(4,glbindtexture);
> hl_o.cmd_insert(5,glcolor, 1, 1, 1, 1);
>
> results in an error:
> ? error: js: clipbank.js: Javascript ReferenceError: moveto is not defined, line 170
>
> so I thought maybe I needed to pass the arguments as a symbol. Since that didn’t produce an error, I thought my chances had at least improved.
>
> Thanks,
>
> Peter.
>
—————————————————-

#102860

You must be logged in to reply to this topic.