Dynamically loading files... Working, but not working..

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Acecool
Posts: 38
Joined: 10 Jan 2016, 18:25
Contact:

Dynamically loading files... Working, but not working..

06 Dec 2016, 22:57

The reason I want to do this is because I created a framework like this for a different programming language and it works very well and is quite useful for my purposes. In addition, it lets me sort my files, libraries, extensions, etc.. how I want to sort them without ever having to add an include / require / etc.. line of code. It handles different realms properly ( based on folder name and ultimately by file-name ) for client / server / both ie shared.. Obviously the AHK framework I am writing is much much simpler.

The AHK framework has a base loader and a full-loader. The base loader only loads the definitions, functions, classes, and libraries that are needed. The full loader loads the base plus hotkeys. Base is so that processes / jobs can run ( such as a stand-alone take screenshot of window, create clickable tray icon asking to move it to public/screenshots in cloud or keep private and open it after selection has been made [ and I am going to, once I figure it out, have it copy the public link to clipboard ] ). Jobs don't need hotkeys to run but will need functions, etc.. this way everything can be organized how I prefer them to be organized and done...

This most likely has been discussed in the past but I am working on my own version which will be publicly released: https://bitbucket.org/Acecool/acecoolah ... k/overview

I may also include my wiki generation system ( have to port from Lua ) to automatically generate documentation based on comments in each file...


Anyways... there seems to be a few issues and possible solutions.

Issues:
If a file doesn't exist, even if you add while not exist wait before an #include ( which will use a static name ) the script fails.
If a file exists and it gets modified, the first version will be used on #include even if you force the script to wait until the changes have taken place prior to including it...

Possible solutions:
You can not launch using just one script ( because of the include issue ) meaning you'd need a launcher which does RunWait to generate the inclusion file. Then after generated it includes a loader file which includes the next ( but it would need to run as a separate instance )...
I could simply run the load-order generator and be done with it, but I don't want to have to run it each time I change the structure.
Compile a pre-loader as exe which generates the files and after it has run, execute the file needed ( but it always loads version - 1 so unless I set it up so it is a separate process so on-close it launches the next phase which runs the right script.. not sure.. ideas? )



Does anyone have any potential solutions? I'm going to sleep on it - 5+ days without sleep because of daily torture.. I'll probably end up setting up several separate loader files, one to generate and one to launch and one to maintain or just 2 and runwait then run and exitapp...


I'm uploading some of the files to bitbucket right now to give a better idea of how it looks along with the bat file to setup the system to your favorite cloud provider ( I use DropBox and OneDrive, etc... but Dropbox for autohotkey files ) which backs up, if exists, the libraries file and autohotkey.ahk file ( so you can use autohotkey.exe to run all of your hotkeys ).... It will also create environment variables and / or shortcuts to special folders ( in the future once I write the step-by-step bat file which lets you choose which features you want.. or I'll make an AHK script for that instead and leave the setup.bat as is for creating backup of Lib and autohotkey.ahk if exists and then creating symbolic link ).

I added a few of the hotkeys for now...
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.
lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: Dynamically loading files... Working, but not working..

07 Dec 2016, 01:56

#Include is a directive. Directives are not commands. Unlike commands, they cannot be executed conditionally. They are not "executed" at all; they are interpreted by the program as it reads the initial script file from disk, before the script starts to execute. Even if you put a "wait" command above an #include, the script won't "wait" until after (possibly long after) the #include has been fully processed and the script has started.
Acecool
Posts: 38
Joined: 10 Jan 2016, 18:25
Contact:

Re: Dynamically loading files... Working, but not working..

07 Dec 2016, 02:34

So I need to have 1 launcher file which runwait create_load_order_file_autoloader.ahk which creates load_order.ahk for full and basic... then run launch_load_order_full/basi.ahk which runs load_order_full/basic.ahk so that they are separately called in separate instances... But how do I run an AHK script to make it create a new tray-icon?
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.
lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: Dynamically loading files... Working, but not working..

07 Dec 2016, 03:06

I don't know the structure of your script, so I don't know how much of that is correct. I suppose that you would only need two scripts: one script to write the #include lines to another file and a second script which includes (or is) that file.
Acecool wrote:But how do I run an AHK script to make it create a new tray-icon?
I either don't understand your question or don't understand why you're asking it. Just run the script.
Acecool
Posts: 38
Joined: 10 Jan 2016, 18:25
Contact:

Re: Dynamically loading files... Working, but not working..

14 Dec 2016, 19:54

Unfortunately run doesn't work for what I need; it doesn't matter how many nested files I use... It also doesn't run all the time which is strange...

I have figured it out... I use cmd to run the script which contains the #include line to run the generated script ( if I use #include *s xxxx.ahk then it is included too early even if I sleep - it is like it is pre-loaded and if it doesn't exist it simply includes nothing but using cmd makes everything run much quicker and doesn't cause any issues )...

But, I have run into a problem.. Running the following script will not execute the Run command unless ALL #include lines are commented out.. Any idea why?

Code: Select all

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\behavior_alter_backspace_to_move_up_directory_in_explorer__winactive_cabinetwclass_backspace.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\calc_sc121__run_calculator.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\capslock__virtual_desktop_task_view_mode_win10.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\hotkey_cycle_audio_devices__pause.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\hotkey_german_spanish_french_math_characters__alt_shift_a_o_u_s_e_i_n_c_l_e_c_r_t_d_o_gt_lt_eq_slash_star_plus_minus_questionmark_exclamation.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\hotkey_screencapture_current_window__alt+f12.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\hotkey_sub_superscript_decimal_conversion_replace_selected_text__win+i_win+o_win+p.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\hotkey_toggle_hidden_file_view__win+h.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\hotkey_toggle_special_keys_language__win+f8.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\hotkey_volume_mixer__media_center_button_sc16d.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\numlock__audible_alert.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\scrolllock__audible_alert.ahk

#include C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\hotkeys\shift_capslock__audible_alert_doubletap_toggle.ahk

Run, C:\WINDOWS\system32\cmd.exe /k C:\Users\Acecool\Dropbox\AcecoolAHK_Framework\addons\_app_hotkeys_dopus.ahk,,Hide,__cmd
Also my framework will be up on bitbucket soon: https://bitbucket.org/Acecool/acecoolah ... k/overview
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.
Acecool
Posts: 38
Joined: 10 Jan 2016, 18:25
Contact:

Re: Dynamically loading files... Working, but not working..

14 Dec 2016, 22:32

If I put those Run commands first, everything works as intended but I would prefer to keep them at the end... At least they work for now...

I will continue working on this, but the framework lets you run all of your standalone scripts ( drag and drop into addons/ ) each time the framework is run and it is intended to run when you run AutoHotkey.exe ( it replaces the AutoHotkey.ahk in your Documents\ folder [ properly based on language by reading the registry ] and makes a backup of the original if one existed.. Same with the INSTALL_PATH\Lib\ folder and symbolically links to your cloud folder such as dropbox\acecoolahk_framework\libraries\...

It also loads all of your hotkeys from the hotkeys\ folder.. Just drop them in there..

Download and try it out: https://bitbucket.org/Acecool/acecoolah ... k/overview




Planned: Template system so if a script requires config by setting up paths, you can use a replacer such as {{FULL_PATH_HERE}} in all the locations and put them into a nested folder in any of the auto inclusion folders ( such as hotkeys, functions, definitions, addons, classes ) and during file-load-order generation those will be converted and moved to their parent directory to be included...

Also planned: Convert the Autoloader function file into a class ( going to move it into assets folder too to keep it out of the way )

Figure out a way so you can run the run_Framework_base/full.ahk file directly ( base is for processes / jobs but only after you've used the launcher file once by running AutoHotkey.exe or framework_launcher.ahk directly )( full isn't meant to be ran stand-alone as the launcher will handle it but it needs to be set up this way so the include will work after the file is generated... although I may be able to remove it if I combine the base and full file into 1 for full but then the run commands wouldn't work, etc.. working on a solution.. ).. Going to move them to assets most likely or rename it with __ for internal file because jobs / processes will need easy access to the base file... but the full file I can move to assets...


Going to make a few changes, but it is ready to test, before posting it in scripts / releases...
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.
Acecool
Posts: 38
Joined: 10 Jan 2016, 18:25
Contact:

Re: Dynamically loading files... Working, but not working..

15 Dec 2016, 06:57

As a note, the reason the Run commands only work before included files is likely because the included files have hotkeys which use Return in the code and instead of return only tying into the hotkey it blocks certain calls to the rest of the file and anything else... Include seems to work, as do hotkeys and a few other things, but not Run.. etc..
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: Dynamically loading files... Working, but not working..

15 Dec 2016, 11:01

Acecool wrote:As a note, the reason the Run commands only work before included files is likely because the included files have hotkeys which use Return in the code and instead of return only tying into the hotkey it blocks certain calls to the rest of the file and anything else... Include seems to work, as do hotkeys and a few other things, but not Run.. etc..
actually its because the auto-execute section gets terminated by one of your #includes

https://autohotkey.com/docs/Scripts.htm#auto
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.
thats why its always safest to put #includes at the bottom

Run won't work, but any other command/funccall/assignment won't work either. because the code is just sitting in limbo:

Code: Select all

; auto exec section
return

func()
{
}

F8::
   ;hotkey
return

Run, myscript.ahk     ; of course this does nothing, how would it ever be executed?


Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 156 guests