using Global… clarification needed

Feb 2, 2007 at 11:58pm

using Global… clarification needed

If I create a Global in one js:

fx = new Global(“fxproperties”);
fx.effects = new Array();

and if I want to manipulate the array “fx.effects” in a different script, do I need to declare:
fx = new Global(“fxproperties”);
in that js as well? I suppose I would, but it seems odd to declare a new Global in different scripts. I guess because they have the same name it doesn’t matter?

Any thoughts?

Peter.

#30092
Mar 1, 2007 at 9:13am

Quote: pnyboer wrote on Sat, 03 February 2007 00:58
—————————————————-
> If I create a Global in one js:
>
> fx = new Global(“fxproperties”);
> fx.effects = new Array();
>
> and if I want to manipulate the array “fx.effects” in a different script, do I need to declare:
> fx = new Global(“fxproperties”);
> in that js as well?

Yep.

> I suppose I would, but it seems odd to declare a new Global in different scripts. I guess because they have the same name it doesn’t matter?

It’s the only way to make something global across different scripts since there is no higher scope than the top level of one script.

>
> Any thoughts?
>
> Peter.
—————————————————-

Mattijs

#95405
Mar 10, 2007 at 12:57am

hmm…doesn’t look like it. here’s an example of creating a global in one js, but manipulating it in another js, without any declaration. the problem with declaring it redundantly is I would probably erase the array if i instantiated a js after I had built an array in the global one!

#P window setfont Arial 9.;
#P number 187 29 35 9 0 9 3 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 188 57 58 131137545 changeit $1;
#P number 82 28 35 9 0 9 3 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 83 56 46 131137545 outit $1;
#P window setfont “Sans Serif” 9.;
#P number 139 29 35 9 0 9 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont Arial 9.;
#P number 42 100 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 41 58 37 131137545 makeit;
#P window setfont “Sans Serif” 9.;
#P message 140 57 46 196617 outit $1;
#P number 167 116 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont Arial 9.;
#P newex 41 78 64 131137545 js junkglob.js;
#P newex 167 95 53 131137545 js junk.js;
#P connect 7 0 1 0;
#P connect 4 0 1 0;
#P connect 1 0 5 0;
#P connect 8 0 7 0;
#P connect 6 0 3 0;
#P connect 9 0 0 0;
#P connect 3 0 0 0;
#P connect 0 0 2 0;
#P connect 10 0 9 0;
#P window clipboard copycount 11;

/*——–junkglob.js creates global array ———-
junk = new Global(“junky”);
junk.things = new Array();

function makeit(){
for (var i=0;i<10;i++){
junk.things[i] = i*2;
post(“njunk.things”,i,junk.things[i]);
}
}

function outit(v){
post(“ndifferent function, same name”,junk.things[v]);
}

/* ———–end junkglob.js——–

/* ———junk.js displays and manipulates global array——–
function outit(v){
outlet(0,junk.things[v]);
}
function changeit(v){
junk.things[v] = v*100;
post(“njunk.things changed”,v,junk.things[v]);
}
/* ——–end junk.js——–

#95406
Mar 10, 2007 at 1:53pm

I am afraid I don’t understand your problem. Perhaps it would be good to post an example with a step-by-step explanation of what you want the patch/js to do.

If you want to fill an array with one js and modify it with another js, you have to put

junk = new Global(“junky”);

in both scripts. That will not overwrite anything.

Mattijs

“it’s the fruit..”

Quote: pnyboer wrote on Sat, 10 March 2007 01:57
—————————————————-
> hmm…doesn’t look like it. here’s an example of creating a global in one js, but manipulating it in another js, without any declaration. the problem with declaring it redundantly is I would probably erase the array if i instantiated a js after I had built an array in the global one!
>
> #P window setfont Arial 9.;
> #P number 187 29 35 9 0 9 3 2001 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 1;
> #P message 188 57 58 131137545 changeit $1;
> #P number 82 28 35 9 0 9 3 2001 0 0 0 221 221 221 222 222 222 0 0 0;
> #P message 83 56 46 131137545 outit $1;
> #P window setfont “Sans Serif” 9.;
> #P number 139 29 35 9 0 9 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window setfont Arial 9.;
> #P number 42 100 35 9 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
> #P message 41 58 37 131137545 makeit;
> #P window setfont “Sans Serif” 9.;
> #P message 140 57 46 196617 outit $1;
> #P number 167 116 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window setfont Arial 9.;
> #P newex 41 78 64 131137545 js junkglob.js;
> #P newex 167 95 53 131137545 js junk.js;
> #P connect 7 0 1 0;
> #P connect 4 0 1 0;
> #P connect 1 0 5 0;
> #P connect 8 0 7 0;
> #P connect 6 0 3 0;
> #P connect 9 0 0 0;
> #P connect 3 0 0 0;
> #P connect 0 0 2 0;
> #P connect 10 0 9 0;
> #P window clipboard copycount 11;
>
> /*——–junkglob.js creates global array ———-
> junk = new Global(“junky”);
> junk.things = new Array();
>
> function makeit(){
> for (var i=0;i<10;i++){
> junk.things[i] = i*2;
> post(“njunk.things”,i,junk.things[i]);
> }
> }
>
> function outit(v){
> post(“ndifferent function, same name”,junk.things[v]);
> }
>
> /* ———–end junkglob.js——–
>
> /* ———junk.js displays and manipulates global array——–
> function outit(v){
> outlet(0,junk.things[v]);
> }
> function changeit(v){
> junk.things[v] = v*100;
> post(“njunk.things changed”,v,junk.things[v]);
> }
> /* ——–end junk.js——–
—————————————————-

#95407

You must be logged in to reply to this topic.