Jump to content

name not defined within scope! $#@%$&^%$!


Eric Castanea
 Share

You are about to reply to a thread that has been inactive for 3642 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

That one's usually pretty easy to track down.  Any variable you use in LSL is only valid where you declare it and invalid anywhere else.  "Where you declare it" is the scope of the variable.  Basically, scope is usually the region between the closest {brackets} around the variable.  So....

integer gQ = 5;   //This variable is valid anywhere.  It is globaldefault{    state_entry()    {        integer i = 2;  // This variable is only valid in state_entry        llSay(0, "See?  \"i\" = " +(string)i + " and \"gQ\" =" + (string)gQ);    }    touch_start(integer num)    {        integer i = 4;  // This is a different variable named "i".  It is only valid in touch_start        if (llDetectedKey(0) == llGetOwner())        {            integer w = 16;  // This variable is only valid within this if test            llSay(0, "See? \"i\" = " + (string)i + "and  \"w\" = " + (string)w);        }    }}

 That's perhaps the best reason for always typing the {brackets}, even when you can get away with omitting them, technically.  So long as the brackets are there, you can use them and prudent indenting to see where the scope of any variable is.  I take the additional step of customarily putting the letter "g" in front of any global variable to remind myself that it has the entire script as its scope. (Thank you, Void. :smileyhappy: )

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3642 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...