# LoadVars() and global variable problems

**URL:** https://forum.kirupa.com/t/loadvars-and-global-variable-problems/128251
**Category:** Uncategorized
**Created:** [November 10, 2004, 8:50pm UTC](https://forum.kirupa.com/t/loadvars-and-global-variable-problems/128251 "2004-11-10T20:50:39Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![clem\_c\_rock](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@clem\_c\_rock](https://forum.kirupa.com/u/clem_c_rock)
#### Post date: [November 10, 2004, 8:50pm UTC](https://forum.kirupa.com/t/loadvars-and-global-variable-problems/128251/1 "2004-11-10T20:50:39Z")

</div>

Hello,

I have an ongoing problem w/ the LoadVars() function and the scope of variables. I would loke to have a situation where I can read the values of a file, set those read values to global variables and use them throughout the program. Now know I can set a text box to recieve the read values but It seems like a copout

Here’s the code I’m using:

\_global.db\_script\_data = new LoadVars();  
db\_script\_data.onLoad = function(success)  
{  
if( success == true )  
{  
\_global.user\_level = db\_script\_data.user\_level;  
\_global.user\_id = db\_script\_data.user\_id;  
}  
else  
{  
txt\_output += "  
!!!No read vars failed!";  
}  
trace( "user\_id: " + user\_id ); //will show user\_id as “1”  
}  
db\_script\_data.sendAndLoad( “verify.php”, db\_script\_data, “POST”);

trace( "user\_id: " + user\_id ); //will show user\_id as undefined

I know there’s probably an easy solution staring me in the face.

Thanks,  
Clem
