Maya Training

Creating characters In Maya and Zbrush

Maya Training

Creating character renders in Maya 2017 and Arnold

Maya Training

Spach-Alspaugh House the complete courseware
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 06-03-2010, 03: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, 03: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, 04: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, 09:14 PM   #4
NextDesign
Technical Director
 
NextDesign's Avatar
 
Join Date: Feb 2004
Posts: 2,982
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

A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2017 SimplyMaya - vBulletin® Copyright © 2000-2017, Jelsoft Enterprises Ltd.