SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Home / forum / Animation / Mel Scripts & Programming / Scope scope scope
Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 06-03-2010, 02:19 PM   #1
Vesuvian
Registered User
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Scope scope scope

Ok, so I'm being a complete newbie and getting stuck with scope. How should I be doing this?

PHP Code:
$fileLoc "C:/output.txt";
global 
$file=`fopen $fileLoc "r"`;

global 
int $readcount 0;
global 
string $curval "";
global 
int $curframe 0;

global 
matrix $frame[18][38];

main();

global 
proc main(){

    
$curval = `fgetword $file`;
    
$readcount++;

    while ( 
size$curval ) > ) {

        if(
$readcount == 686){
            
$readcount 1
            drawmatrix
();
        }

        if(
$readcount == 1){
            
$curframe $readcount;
            print ( 
$curval "\n" );
        }else{
            
addmatrix();
        }

        
$curval = `fgetword $file`;
        
$readcount++;
    }

    
fclose $file;
}

global 
proc addmatrix(){

    
int $count $readcount 1;
    
    
int $y 0;
    
    while(
$count 38){
        
$count -= 38;
        
$y++;
    }    
    
    
int $x $count;

    
$frame[$y][$x-1] = $curval;


I get loads of errors about things not being defined so I'm certain it's a scope issue.
Vesuvian is offline   Reply With Quote
Old 06-03-2010, 02:42 PM   #2
Vesuvian
Registered User
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Aha, gotta declare the vars again in each proc.

How do I globally define the $file, since I don't know datatype?
Vesuvian is offline   Reply With Quote
Old 06-03-2010, 03:37 PM   #3
Vesuvian
Registered User
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

All fixed. To anyone who stumbles across this with the same problems:

1) global variables need to be defined in the procedure as well as outside the proc.

2) file id's can be defined globally by doing:

PHP Code:
global int $file;
$file = `fopen $fileLoc "r"`; 
Vesuvian is offline   Reply With Quote
Old 06-03-2010, 08:14 PM   #4
NextDesign
Technical Director
 
NextDesign's Avatar
 
Join Date: Feb 2004
Posts: 2,988
Thanks: 33
Thanked 532 Times in 471 Posts
Default

They can also be defined in one line.
PHP Code:
global int $file = `fopen $fileLoc "r"`; 
__________________
Imagination is more important than knowledge.
NextDesign is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.