Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   Scope scope scope (https://simplymaya.com/forum/showthread.php?t=33854)

Vesuvian 06-03-2010 03:19 PM

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 06-03-2010 03:42 PM

Aha, gotta declare the vars again in each proc.

How do I globally define the $file, since I don't know datatype?

Vesuvian 06-03-2010 04:37 PM

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"`; 


NextDesign 06-03-2010 09:14 PM

They can also be defined in one line.
PHP Code:

global int $file = `fopen $fileLoc "r"`; 



All times are GMT. The time now is 02:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018