Jump to content

Function In My Include script Not seen - (Moved)


Recommended Posts

I have many scripts with dozens of UDF's that I want to put into my own Include file.

I moved a UDF from one of my scripts to my own "Include file"

I added the include script file to my script and the script ran OK.   (#include <C:\folder\MyInclude.au3>)

I thought "Wow", lets put a bunch of my UDF's into my include script and reduce my 1200 line script a whole bunch.

No matter what I do, the second UDF that I moved out of my main script causes an error "Undefined function  Abc2()" when I attempt to run the script.

I have "include-once" at the top of the include script file.

Thanks for your help

Link to comment
Share on other sites

  • Developers

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

You will have to share some code/files in case you want a real answer to your issue! 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Consider this example:

This is MyInclude.au3

#Include-once

Func Abc()
    Msgbox(0,'','Hello from "ABC" ')
EndFunc

Func Def()
    Msgbox(0,'','Hello from "DEF" ')
EndFunc

This is my main script:

#include <C:\Folder\MyInclude.au3>

Abc()  ;Runs OK if Def() is commented out

Def()   ;Produces error "Undefined function" script does not run

This is the structure that I see in all of the existing AutoIt "Include" scripts that  am currently using.

THIS particular script is not in the same location as all of the other "Includes" , that is why I have the path in the "Include" statement (Which works for ABC() )

Why does this not work??

Thanks for your help

Link to comment
Share on other sites

1 hour ago, AutoitMike said:

Why does this not work??

Hmm, it works for me.

Put the filepath in quotes

#include "C:\Folder\MyInclude.au3"

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

3 hours ago, AutoitMike said:

Using the quotes instead of the brackets produces the same exact behavior.

Try the following test scenario :

1. Create two folders C:\Foldermain and C:\Folderudf  (the folder names do not matter in particular)

 2. Create the main script MyScript.au3 in C:\Foldermain

#include "C:\Folderudf\MyInclude.au3"
Abc()
Def()

3, Create the udf script MyInclude.au3 in C:\Folderudf

#Include-once

Func Abc()
    Msgbox(0,'ABC : ','Hello from function ABC in the mainscript' & @CRLF & @ScriptFullPath)
EndFunc

Func Def()
    Msgbox(0,'DEF : ','Hello from function DEF in the mainscript' & @CRLF & @ScriptFullPath)
EndFunc

4. Now start MyScript , no matter if from the SciTE Editor with F5 or as compiled .exe.

Result for me : it works

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

OK,

I figured it out.

 

You can not have "Include files" in multiple locations throughout the PC. (at least within a single script). I think that AutoIt wants all include files in one location. Maybe this is a bug??

Once I moved MyInclude.au3 to the same location as all of the other include files and included it the same way that I include all my other "Includes"". IE   #include <MyInclude.au3>,  it works.

 

Edited by AutoitMike
Link to comment
Share on other sites

On 9/1/2023 at 7:50 AM, Musashi said:

Result for me : it works

Result for me : it works too
But this is quite strange : If Autoit sees the include, both funcs should work, if not none should work

Abc()  ;Runs OK if Def() is commented out

Def()   ;Produces error "Undefined function" script does not run
Edited by mikell
Link to comment
Share on other sites

  • Developers
4 hours ago, AutoitMike said:

You can not have "Include files" in multiple locations throughout the PC. (at least within a single script). I think that AutoIt wants all include files in one location. Maybe this is a bug??

Noway and this statement is totally incorrect! Read the helpfile on how it works and you'll (hopefully) understand how it works!

In case you insist this is an bug you will have to provide an replicator script with the exact details of how you use it and what goes wrong!

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Here's something to consider, all of your includes should be at the top of your script, before you call any functions. Also, the order of your includes could matter. I don't think that the example you gave is something that you've tested, because that does work no problem for everyone here (myself included).

How sure are you that the "missing" function is in fact included in your file? As long as it's there, there shouldn't be a reason why it would fail and not be able to find the file.

Here's another topic on include file organization: 

Keep in mind also that even if you include everything into a script, that only means everything will (or should) work from that main script. You still need to make sure that none of your includes have references to things that exist outside of their own files. Otherwise when you include just a single file or two instead of the whole set of them, you can get undefined functions. I would recommend running the "SyntaxCheck Prod" tool in SciTE (Ctrl + F5) on each of your include files to make sure there's nothing missing in the includes itself.

 

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

Mister Squirrle

Thanks for the input.

1. All of my includes are at the top of my main script.

2. My custom "Include" is listed last in a list of about 10 includes.

3. I Moved my include script to the same location as all of the other "Include" scripts, removed the path part of the include statement and the problem went away,

4. The include script makes no references outside of the script or any other functions

The name of the function was always correct and never changed.

The complete solution was to move the location of the script to the same locations all of the existing include scripts (The default AutoIt location).

Link to comment
Share on other sites

2 hours ago, AutoitMike said:

The complete solution was to move the location of the script to the same locations all of the existing include scripts (The default AutoIt location).

While this is a workable solution, it is not the preferable one.

Take a look at : https://www.autoitscript.com/wiki/Adding_UDFs_to_AutoIt_and_SciTE

Excerpt :

Creating a Personal Include Folder

Begin by creating a new folder to hold the additional UDFs - it is recommended that you do NOT put this folder in the AutoIt install folder (or it will get overwritten when you upgrade). 

 

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

If it only worked when you put the scripts in the AutoIt install/include folder, it's likely because of your #include <> instead of #include "".  Take a look at the help file notes for #include https://www.autoitscript.com/autoit3/docs/keywords/include.htm

 

I know you mentioned that you did try putting them in quotes already, but keep in mind that you either need to provide the relative path or the absolute path in quotes. So if the include file is in the same folder then #include "file.au3" works, but if it's in a different folder then you need to do something like #include "C:/AutoIt_Includes/file.au3" or #include "Includes/file.au3" (assuming the Includes folder is in the same folder as the script). Also if you provide relative paths and then move the file and not the includes you'll get errors.

 

Maybe you know all of that, just mentioning it as it's the issue that comes to mind from what you've said. 

 

However if it's working now and you're okay with that, then do whatever works. As mentioned though it's not recommended. If you move the include files back somewhere and still have a problem, try using the full path to the file (hold shift and right click on a file to get a "copy as path" option in the menu) in quotes on the #include line. If you still have errors, provide the exact script text that you're using (at least the include part) and something like a screenshot of an explorer window where the include files are, with the address bar visible if you want more help. 

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...