1. Calling a function from within a function

Hello all!

Here's another beginner questions that has me stumped!

I want to call a function from within a function and set the variable to the
returned value.  Here's what I coded and the error message I got back:

sequence DirectoryPath
object FileName
object Path
object File
atom Lines
object strings
object DataRead
object OrdersFileExist


function ReadFactionOrders(integer FactionNumber)
    
    DirectoryPath = {"c:\\warcry\\orders"}
        -- seperated the directory path out for error handling
    FileName = sprintf("faction%d.ord", {FactionNumber})
        -- seperate variable for filename, need to use this twice
    Path = chdir(DirectoryPath) 
        -- sets the working directory to c:\warcry\orders
    File = open(FileName, "r")  
        -- opens the text file, ex. opens faction1.ord orders file
    Lines = CountLines(FileName)        
        -- calls the countlines function to see how many lines of text is
        -- in the file

The last line is what gives me the following:

H:\getorders.e:41
CountLines has not been declared
    Lines = CountLines(FileName)        
                     ^
Countlines is a function that should return how many lines on text is is the
file we are looking at, but for some reason it thinks it's another variable.

Sorry if I'm missing something obvious, but for the life of me I don't know
what!

Thanks!!
Rich

p.s., to give credit where it's due, I got the countlines function out of the
archive, sorry, don't remember the author, but it saved me alot of coding!!
It was just what I needed so a big thank you!!

new topic     » topic index » view message » categorize

2. Re: Calling a function from within a function

Rich Klender wrote:
> 
> Hello all!
> 
> Here's another beginner questions that has me stumped!
> 
> I want to call a function from within a function and set the variable to the
> returned value.  Here's what I coded and the error message I got back:
> 
> sequence DirectoryPath
> object FileName
> object Path
> object File
> atom Lines
> object strings
> object DataRead
> object OrdersFileExist
> 
> 
> function ReadFactionOrders(integer FactionNumber)
>     
>     DirectoryPath = {"c:\\warcry\\orders"}
>         -- seperated the directory path out for error handling
>     FileName = sprintf("faction%d.ord", {FactionNumber})
>         -- seperate variable for filename, need to use this twice
>     Path = chdir(DirectoryPath) 
>         -- sets the working directory to c:\warcry\orders
>     File = open(FileName, "r")  
>         -- opens the text file, ex. opens faction1.ord orders file
>     Lines = CountLines(FileName)        
>         -- calls the countlines function to see how many lines of text is
>         -- in the file
> 
> The last line is what gives me the following:
> 
> H:\getorders.e:41
> CountLines has not been declared
>     Lines = CountLines(FileName)        
>                      ^
> Countlines is a function that should return how many lines on text is is the
> file we are looking at, but for some reason it thinks it's another variable.
> 
> Sorry if I'm missing something obvious, but for the life of me I don't know
> what!
> 
> Thanks!!
> Rich
> 
> p.s., to give credit where it's due, I got the countlines function out of the
> archive, sorry, don't remember the author, but it saved me alot of coding!!
> It was just what I needed so a big thank you!!

Make sure that the function CountLines is declared above the function
ReadFactionOrders or any other function or procedure that uses it.

If it is included from a separate file make sure the include statement is above
ReadFactionOrders or any other function or procedure that uses it.

In Euphoria everything must be declared before it is used.

--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Calling a function from within a function

Thanks, I knew it was something obvious!!  I had it tacked on at the
end of the file I was working in.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu