Global Variables problem

Ask a Question related to Macromedia Director Lingo, Design and Development.

  1. #1

    Default Global Variables problem

    Hi there.. i know this is a very newb question, but any way... need to know something.

    I had declared a global variable this way:


    on exitFrame me
    global gLife
    gLife = 4
    set the text of member("vida_text") = "Vida: " & gLife & "/4"
    end

    when i play the movie, i can see that the text of member vida_text is changed to "Vida: 4/4", that's cool, i can even see the variable value on the Message window when I type: ShowGlobals. For what i know this variable is avaliable ALL the time the proyector is running, but when i try to use it for example in a button with this lingo:


    on mouseUp
    if member ("p1_r1").hilite = 1 then
    put gLife
    set the text of member("vida_text") = "Vida: " & gLife & "/4"
    else
    beep
    end if
    end


    I get this error EVEN B4 i start the movie:


    Variable used before assigned a value

    put gLife?

    How can this be posible is the gLife variable is declared as a GLOBAL variable and i can see the value that it contains?


    The truth is out there!
    Rodrigo Alarcon webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. Global Variables
      I would like to know the preferred way in which to define, store, and retrieve global varialbes in asp.net applications. I have read through past...
    2. Global variables in AS3
      The documentation for AS3 tells me that a variable set as 'public' will be available everywhere. If I set public var myvar:String; at the top of...
    3. Global/persistent variables
      I'm analysing a conversion of a system from Oracle to PG. The system in case uses a lot of PL/SQL packages and lots of them uses public/static...
    4. Problem with global variables
      Hi All, I'm turning mad with global variables... In created a simple test script with 2 functions which worked fine but the other one i need...
    5. Global variables - application variables vs include file
      What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include...
  3. #2

    Default Re: Global Variables problem

    You need to define it as a global in every script you want to have access to
    the variable:

    global gLife
    on exitFrame me
    gLife = 4
    set the text of member("vida_text") = "Vida: " & gLife & "/4"
    end


    global gLife -- if this handler is in the same script you don't need this
    line. Otherwise, you do.
    on mouseUp
    if member ("p1_r1").hilite = 1 then
    put gLife
    set the text of member("vida_text") = "Vida: " & gLife & "/4"
    else
    beep
    end if
    end


    "Rodrigo Alarcon" <webforumsuser@macromedia.com> wrote in message
    news:bqlo2c$pgs$1@forums.macromedia.com...
    > Hi there.. i know this is a very newb question, but any way... need to
    know something.
    >
    > I had declared a global variable this way:
    >
    >
    > on exitFrame me
    > global gLife
    > gLife = 4
    > set the text of member("vida_text") = "Vida: " & gLife & "/4"
    > end
    >
    > when i play the movie, i can see that the text of member vida_text is
    changed to "Vida: 4/4", that's cool, i can even see the variable value on
    the Message window when I type: ShowGlobals. For what i know this variable
    is avaliable ALL the time the proyector is running, but when i try to use it
    for example in a button with this lingo:
    >
    >
    > on mouseUp
    > if member ("p1_r1").hilite = 1 then
    > put gLife
    > set the text of member("vida_text") = "Vida: " & gLife & "/4"
    > else
    > beep
    > end if
    > end
    >
    >
    > I get this error EVEN B4 i start the movie:
    >
    >
    > Variable used before assigned a value
    >
    > put gLife?
    >
    > How can this be posible is the gLife variable is declared as a GLOBAL
    variable and i can see the value that it contains?
    >
    > The truth is out there!

    alchemist Guest

  4. #3

    Default Re: Global Variables problem

    > How can this be posible is the gLife variable is declared as a GLOBAL variable and i can see the value that it contains?
    because is declared but not invoked in the behavior
    >
    on mouseUp
    global gLife -- invoke the variable first
    if member ("p1_r1").hilite = 1 then
    put gLife
    set the text of member("vida_text") = "Vida: " & gLife & "/4"
    else
    beep
    end if
    end

    salu2

    D.
    > The truth is out there!
    Daniel Pliscoff Guest

  5. #4

    Default Re: Global Variables problem

    You can declare globals both inside or outside of a handler. It´s generally
    better to declare your global variables at the beginning of the script,
    outdide of handlers... say... as the other guys have already mentioned, you
    must declare your globals in every SINGLE script you use them. We all know
    that does not always happen in other programming languages but hey!!! say
    hello to Lingo.

    global gLife
    global mLife
    global pDeath

    -- and then place the handlers...

    on mouseUp
    bla bla bla
    bla bla bla
    end



    "Rodrigo Alarcon" <webforumsuser@macromedia.com> escribió en el mensaje
    news:bqlo2c$pgs$1@forums.macromedia.com...
    > Hi there.. i know this is a very newb question, but any way... need to
    know something.
    >
    > I had declared a global variable this way:
    >
    >
    > on exitFrame me
    > global gLife
    > gLife = 4
    > set the text of member("vida_text") = "Vida: " & gLife & "/4"
    > end
    >
    > when i play the movie, i can see that the text of member vida_text is
    changed to "Vida: 4/4", that's cool, i can even see the variable value on
    the Message window when I type: ShowGlobals. For what i know this variable
    is avaliable ALL the time the proyector is running, but when i try to use it
    for example in a button with this lingo:
    >
    >
    > on mouseUp
    > if member ("p1_r1").hilite = 1 then
    > put gLife
    > set the text of member("vida_text") = "Vida: " & gLife & "/4"
    > else
    > beep
    > end if
    > end
    >
    >
    > I get this error EVEN B4 i start the movie:
    >
    >
    > Variable used before assigned a value
    >
    > put gLife?
    >
    > How can this be posible is the gLife variable is declared as a GLOBAL
    variable and i can see the value that it contains?
    >
    > The truth is out there!

    Arturo Toledo Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139