|
Post by Trey on Jul 7, 2021 3:35:18 GMT
I'm loading variables using the INPUT FROM FILE method, and the next lines after I load the variables have a dependency on some of the variables. Has anyone else experienced this?
My sequence goes like this:
1. I run a python script via RUN VIA CMD /c that pulls a set of variables from a table row and writes them out to INPUT.txt 2. I then INPUT FROM FILE those variables, one of them is some INTEGER n 3. I then run a MESSAGE PROMPT that displays something like "The value of n is %INTEGER%!"
If I just run those in three lines, it'd tell me the value of %INTEGER% is zero or null, even though I can check the INPUT.txt file I output and see that %INTEGER% is not zero!
Now, you're probably thinking that the macro is running the next line before the python script writes out INPUT.txt! Yeah, I figured that might be the case too, so now I do this:
1. I define a %BOOLEAN% variable to be FALSE 2. I run my python script, which writes out %BOOLEAN% as TRUE now, in addition to my %INTEGER% 3. I INPUT FROM FILE with VARIABLES::REFRESH from my INPUT.txt 4. I then use IF | BOOLEAN VARIABLE | %BOOLEAN% | IS TRUE | CONTINUE to hold until %BOOLEAN% is TRUE, meaning INPUT.txt was written out by my script and had to have been imported to the variables.
Unfortunately, I'm still running into race conditions, it's almost as though in some cases, where there's a lot of variables to pull in from INPUT.txt, %BOOLEAN% gets written and acted on before the other values. That seems weird to me, but I don't have any other ideas. I know my python script is writing the correct variables into INPUT.txt.
Please help, this is driving me crazy.
|
|
|
Post by philranger on Jul 7, 2021 12:01:26 GMT
Hello,
I may be wrong, but I would think that the file isn’t re-read at every input, but kinda buffered so your python actualises the file but mmm doesn’t know it?
|
|
|
Post by Trey on Jul 7, 2021 13:57:18 GMT
Hi Phil,
Yeah, it seems like MMM isn't fully reading the file and loading all the variables before it moves on to the next line in the macro. There's some race condition going on here, I have my variables open while my macro runs and the values I can see in the variables are not being passed to the macro line. This is really frustrating.
|
|
trey
Junior Member
Posts: 12
|
Post by trey on Jul 7, 2021 14:31:09 GMT
Edit: Just for completeness, adding a screengrab of the sequence where you can see I'm paused at Line 6, and you can see the Variables have been set from INPUT.txt. Also, embedding images doesn't seem to work, so another link to imgur for this one. Imgur link: imgur.com/a/p5hu0cE
Hopefully you can see this screengrab, otherwise I posted it on imgur here: imgur.com/gallery/5amhLKvThis macro has run all the way to Line 11, where I paused it. You can see in Line 3 I run a python script with a cmd line arg. This script outputs an INPUT.txt that looks like: You can see in the screengrab that Line 4 used INPUT FROM FILE to load those variables, and you can see looking at the Variables displayed that yes, those variables are loaded by the time I get to Line 11. At Line 8, because %INTEGER1% is greater than 0, it goes to MACRO LINE Reset, where it runs a message prompt that uses %INTEGER1%. Now remember, in order to even get to Line 11, %INTEGER1% HAD TO BE GREATER THAN 0! But look at the message prompt, it's saying %INTEGER1% is 0, even though in the Variables it clearly isn't. What is going on here?!?! I'm fairly new to MMM, so please let me know if it's my macro scripting syntax. I've meticulously gone through the documentation, but in some places it feels like it doesn't quite cover all the use cases in the examples. Steve Here's my Event Logger output, where again, %INTEGER1% is definitely 2 but the Message Prompt says 0
|
|
trey
Junior Member
Posts: 12
|
Post by trey on Jul 7, 2021 17:39:50 GMT
I think I see what might be happening...
Does GOTO MACRO LINE re-initialize the variables???
|
|
|
Post by Steve on Jul 8, 2021 3:36:16 GMT
Hi trey I hope you don't mind but I edited your post to include the images you embedded. Imgur.com provides a link like this imgur.com/gallery/5amhLKv but this forum needs the full path "https://i.imgur.com/DFmgt8N.jpeg". To import it from Imgur I needed to right click the image and copy the image location. I prefer postimages.org/ for posting images. They provide the full path. You can also just type in the path of your image like this without the quotes "https://i.imgur.com/DFmgt8N.jpeg". Without the quotes it will automatically add it to the post. Its not a race condition and your not crazy. Yes, it is the GOTO sending your macro back to the start effectively clearing your variables. You need to 'Enable variable saves' and yes you need the pro version to do this for now. I'm adding this option to the free version with the release of the next version and turning it on by default. It shouldn't be muted.
GOTO effectively searches for your goto pattern top-down. If it can't find it down from your line number it will hit the top and go back down the list. This 'hitting the top' and starting from line number 1, from MMM's perspective is a fresh macro run. I'm trying to think how you can get around it now without purchasing the pro version or waiting for the next release but it's not going to be pretty.
|
|
trey
Junior Member
Posts: 12
|
Post by trey on Jul 8, 2021 17:48:52 GMT
Thanks so much Steve ! Good news, I'm working with Mini Mouse Macro Pro, so I'm looking forward to testing it with enabling variable saves later today Quick question I hope you see without me having to start a new thread... I know I can define custom variables using 1 | RUN ACTION | DEFINE STRING VARIABLE | %farm%::barn but can I do it similarly using INPUT FROM FILE if I have a file input.txt that looks like this...? farm::barn status::TRUE count::4
|
|
|
Post by Steve on Jul 9, 2021 6:19:46 GMT
Thanks so much Steve ! Good news, I'm working with Mini Mouse Macro Pro, so I'm looking forward to testing it with enabling variable saves later today Quick question I hope you see without me having to start a new thread... I know I can define custom variables using 1 | RUN ACTION | DEFINE STRING VARIABLE | %farm%::barn but can I do it similarly using INPUT FROM FILE if I have a file input.txt that looks like this...? farm::barn status::TRUE count::4 Yes that will work. 1 | RUN ACTION | INPUT FROM FILE | VARIABLES::NO_REFRESH::C:\Macro\File\input.txt 2 | RUN ACTION | MESSAGE PROMPT | farm: %farm%'\n'status: %status%'\n'count: %count%::input.txt Input Check::0::Information
|
|