Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

Scripting variables Flash Client

AduanAduan Member Posts: 40 ✭✭ - Stalwart
Since the update with the drag n drop, i'm getting some nasty nasty errors in the flash client.

On load, i loaded an object with settings for my little 'system'.
var arSystem = {sipPrio: 'Health',Announce: 'No',GroupTarget: 'No'};

The object is created without any errors, however my old method to access the object now throws an error:
arSystem['Announce'] = 'Yes'

Now causes:

Error in Button Script 2:
ReferenceError: 'arSystem' is undefined

What changed with the new system regarding these variables and is there a workaround for this issue?



Comments

  • TaeltwoTaeltwo Member Posts: 55 ✭✭ - Stalwart
    edited March 2016
    I'm assuming you mean the html client, the problem you're running into is that every alias/trigger/whatever script is sandboxed into its own namespace now.

    So instead of defining globals, if you need to access something between scripts, you should define it as a property of the client object.

    Just change:

    var arSystem = {sipPrio: 'Health',Announce: 'No',GroupTarget: 'No'};

    to:

    client.arSystem = {sipPrio: 'Health',Announce: 'No',GroupTarget: 'No'};

    and it should work.

    You don't need to change arSystem[Announce'] to client.arSystem['Announce']. You only need to do this for variable declarations, not for references to variables.

    (This is actually similar to how global variables work in JavaScript anyway. When you do var blah = "blah"; in browser JavaScript, that's actually just shorthand for window.blah = "blah";)
    Aduan
  • AduanAduan Member Posts: 40 ✭✭ - Stalwart
    Thanks!
  • AntoniusAntonius Member Posts: 5,040 @@ - Legendary Achaean
    Taeltwo said:
    (This is actually similar to how global variables work in JavaScript anyway. When you do var blah = "blah"; in browser JavaScript, that's actually just shorthand for window.blah = "blah";)
    That's massively misleading. The var keyword is definitely NOT a shorthand for assigning a variable on the window object. The var keyword indicates that the variable is local to the current scope, so it's only equivalent to calling window.blah = "blah" if the current scope is the entire window (i.e. you're not inside a closure). If you want something that's equivalent to window.blah = "blah" regardless of scope drop the var keyword entirely.
    Utianima
  • TaeltwoTaeltwo Member Posts: 55 ✭✭ - Stalwart
    edited March 2016
    Antonius said:
    Taeltwo said:
    (This is actually similar to how global variables work in JavaScript anyway. When you do var blah = "blah"; in browser JavaScript, that's actually just shorthand for window.blah = "blah";)
    That's massively misleading. The var keyword is definitely NOT a shorthand for assigning a variable on the window object. The var keyword indicates that the variable is local to the current scope, so it's only equivalent to calling window.blah = "blah" if the current scope is the entire window (i.e. you're not inside a closure). If you want something that's equivalent to window.blah = "blah" regardless of scope drop the var keyword entirely.
    Yeah, I guess that was unclear. When I said "This is actually similar to how global variables work", I meant that to specify that I was talking about var statements in what is commonly thought of as JavaScript's "global" scope, not var statements in general.
Sign In to Comment.