• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

Simple Resizable GUI

Here’s a simple resizable GUI

Update to Resizable GUI

Update to Resizable GUI

The video discusses the use of local static variables instead of global or regular static variables to avoid issues when calling labels again, and provides solutions to common issues related to static and global variables in programming.

  • 00:00 Joe and Isaiah fixed a variable issue in a resizable GUI function by creating the GUI without loading the variable and passing it through GUI control, while the speaker added a parameter to close the program when the GUI is closed and reminded that variables inside functions are local by default.
    • Joe Lyons and Isaiah encountered an issue with a variable in a resizable GUI function, and the workaround was to create the GUI without loading the variable and then use GUI control to pass the variable after.
    • The speaker created a GUI with a resizable feature and added a parameter to close the program when the GUI is closed.
    • When working with functions, variables inside the function are local by default and lose their information as soon as you go out of that function.
  • 03:35 Use local static variables instead of global or regular static variables to avoid issues when calling labels again.
    • Be concise and remove redundant words in the TLDR.
    • When a function returns, the thread is gone and the variable loses its information, causing issues when calling the label again.
    • The best solution for the issue is to use a local static variable instead of a global variable or a regular static variable.
  • 06:36 A static variable in a function retains its value between calls, but if not reset, it will keep its previous value.
    • Creating a static variable in a function allows it to retain its value between calls.
    • If a static variable is not reset, it will retain its previous value on the next call.
  • 09:39 Static variables in JavaScript remember their value from the previous call unless a new value is assigned.
    • The issue is that static and global keywords get executed before the script starts, so declaring a variable as static should be done separately from initializing it.
    • Static variables remember their value from the previous call unless a new value is assigned.
  • 12:01 The solution to the blank output issue is to automatically fill it and using a global variable may be necessary in certain cases.
    • The issue with the return value was resolved, but the output is still blank and the solution is to keep it automatically filled.
    • Using a global variable may be necessary in certain cases, such as when a function is called by a different thread, to ensure that the variable retains its value.
    • The speaker discusses the process of removing redundant calls and saving a value as one, but encountering an issue when trying to close it.
  • 15:40 Static and global keywords cannot have parameters, but passing a parameter to a static or global variable can be done by putting it on its own line outside of the keyword.
    • Static and global keywords should only have the initial value and cannot have parameters, but passing a parameter to a static or global variable can be done by putting it on its own line outside of the keyword.
    • Using a function to keep an object static will keep the instance of that object and its value throughout the course.
  • 17:32 When using recursive functions, avoid using static variables and instead make parameters global by labeling them with “ref” to ensure changes affect the top variable.
    • Static variables are commonly used in recursive functions to keep track of the level, but if the variable is replaced on the second call, there is no point in having it.
    • To make a parameter global, label it by ref, which implies that any changes made to it will affect the variable it refers to at the top.
  • 20:21 Learn AutoHotkey with 5+ hours of content and a money-back guarantee.
    • Take the intro to AutoHotkey course to learn the right path and stay focused with over five hours of content and a money-back guarantee.

hey everyone it’s joe Glines here from the-Automator and Isaias’shis webcam isn’t on at the moment but he’s still here andso he’s helping me i had this resizable gui function that i had written years ago actually mastery mainstream really kind of helped me create it and then i adapted and changed and stuff and we during the last webinar we ran into this really weird interesting issue so this is just a side note so what we figured out was and actually Isaias’s and i after the fact yesterday played for what
like 30 minutes or 45 minutes somewhere in there yes trying to figure out what was going on and it was still there’s just something in the file that i was the variable that i was trying to load was causing an issue so the work around which which actually jackie saw live on the webinar but when we googled it they that was really the same solution right was too it is create the gui don’t load it here which is what i used to do and then use gui control to pass the variable to the gui after the fact and so that negates the the problem even
to me it’s voodoo because i’m like it’s the same thing but whatever okay so the purpose of this video yeah about three weeks ago i was working in this function and i’m like hey you know be kind of cool is what if after i create this gui like if i hit this Hotkey right now here’s the gui it creates and like i said it’sresizable right which is very convenient for something and i have it in my library but if i kill this it just closes this gui but what if i passed a parameter when i used it like
this one and it said when i close it it closes the program and i’m like that could be really helpful this is a value and we’ll set the default value to zero so it’s not on but if i want it on i can just turn it on right when i call it what i ran into was this weird to me very weird thing was i first just tried passing the parameter and then using it and it didn’t work and then i tried making it global or sorry actually i didn’t say i said i said i tried making it static up here that didn’t work and then i tried global
that didn’t work and then i said screw it let me put it into a different variable that actually worked but i this is where i’m like okay like it’s actually a very common confusion yeah it is a it is a confusing problem so if you’re working with functions probably you already know thatall the variables that are inside a function are local by default right so that means that any variable that you use inside the function right they only have the information when you are inside that function and as
soon as you go out of that function those variables lose the information so you cannot retrieve them right now yeah so that’s something very common right you know that probably now here’s the deal when you create thethe control so you create the control right here okay you have a return right there what happens then is that the function goes out and all the variables lose their information so that’s the reason why the first attempt that you did like okay let me use the parameter well the parameter was good
up to line 14. after that when you try to use it on line 25 well you’re outside of the function and that variable has no information anymore right yeah i would maybe i would phrase it and i could be wrong but it’s like outside of that instance of calling it but i get your i get what you’re saying yeah exactly it is it is correct what you said it’s just that what what when so as soon as you hit the return right here the the threat is over and that threat yeah right so the thread is gone and the variable loses its
information and now when you call thisthis label right here that is a new thread and that thread does not have any information for that variable because that variable was part of a function so basically that’s the idea that’s the reason why this down here didn’t work at the first time because of that return right here yeah fine so now let’s go to the second part okay so let’s go to the part in which okay i want to make and this is on just go ahead and try and write it let’s go ahead and do
the following static and you wanted to do exit the right so this is your first attempt right now why wouldn’t this work basically and and and i will tell you the correct solution in my mind okay so global is one of the solutions right and it works for you now the reason why i wouldn’t recommend it is because it is a global variable and it’s going to be an issue somebody can change it for you without knowing those kind of things so the best solution is a static now the correct solution right now would be
exit the app equals vta and make this parameter exit the app right so that would be like the parameter is passed to a local static variable that is the solution for me now why do i need two different variables right why can’t i just say like static at the app right so what happens is that all the parameters those variables that you create as parameters are special variables you cannot make them global and yet cannot make them static cannot make because they’re special they’re kind of like special parameter so so all those
variables right here you have them right yeah so that’s the part that made you a little bit like it confused you a little bit right so basically what i would do is exactly what you mentioned like i would make a static variable that is called exit the app and to that variable i would pass the parameter that you just passed and now i get it now yeah right and now in this caseeverything is gonna it should and basically hold on this x down here would be the one that you would use down here yeah yeah right and to clarify for
people if you’re not used to static static at least trying to there’s several things you can do but basically it keeps the memory after multiple calls is that right is one way exactly so as we explained at the beginning yeah so as we explained at the beginning in functions when you finish the function when you hit the return right here every single variableloses its value so when you call it again it is empty right but when you create a staticvariable what happens is that that variable when you hit the return down here
that variable does not loses its contents so the idea now is that whenever you pass the and i’m just thinking something because right now what i’m saying is yeah you are passing it right here with a zero right so i wouldi’m just thinking whether on the second call if it is empty if it is going to return back to zero that’s what i’m thinking right now what i would say is that’s the default value right i would be passionate this is a default that’s that’s creating a default variable
right that would be a default right but if you put zero you’re passing zero as the default value right which is what i was saying yeah rightbut in general what what the the idea that we were just discussing is that well if you have a static variable on the next call whatever it had before is not going to be deleted by default okay unless you’re ready to right it’ll stay right right so whatever you pass to it it will stay it would be sticky it would be static and that’s the the hence the the key word would be static on the next
call as well so in this case on your call you pass a one right and that one is going to be saved into the static variable right and for the next call if you on the next call pass it without this right on this second call that variable should still benumber one and we could test it by exit via could just do this and if you run the script on the first try it would show empty right exit the app would be empty right and on the second call it should actually show one but i didn’t see the one right yeah which is what i was actually afraid
of because even though you’re passing the second the second call you’re actually passing a blank to it which is funny it is but that would be default but i wouldn’t the see i think you have the order backward like the second call it only if you when you have the one there should it have a value but the weird part is i never saw it have a value no but the problem is here’s the thing here’s the it is not obvious and that’s the part that i’m actually kind of like thinking of initialize that with a zero
try it again i have a one right on the second message box i should get up to there you go that means that the variable is static and every time i call the plus plus it is actually just adding to whatever variable that that was there before so but when you let’s make it zero here let me pass it as right that should do the same that’s my idea that’s that’s the idea that’s what we’re trying to that should do but that’s not what it does the problem is and this is the issue static and global keywords get executed
before the script even starts so basically i should declare it static but this should be done like this that’s what happens yeah it should not be done in the same keyword here right now not on the same line because this line this static line gets executed no that’s what i said though was not on the same line right so let’s go ahead and move on right let’s try it now so now i have a number one and on the second call i should still get a one but that’s what i meant so you see when your variable when you’re and
that’s the the keyword the thing that i wanted to tell you before if you put a zero in there it is going to pass a zero to it right so now what i want no you don’t want because on the second call you want it to still stay at one no i don’t okay i only wanted to stay at one if i put a one there yes i want the default to be zero unless i put something that it’ll okay i understand i understand your point now butwhat i thought is that and that’s the idea of a static variable the idea of the static variable is that
in the second call it should remember whatever i put the first time i i called it yeah but right you were saying that because the return issue we had to get it down you know yeah in the same instance down below right yeah yeah now can you run it right now and let me let me verify something because there’s something that yeah it is still blank set and that’s the funny thingwhat i would do that would keep i it actually automatically as it puts whatever is there but in your case okay if that’s what you need so you want
it to be full so you don’t want to close the appand on the second call it would be false that’s perfect that’s exactly what you wanted but in my case for example when i use the static variables it’s just for me to keep certain type of information like and and even if i don’t pass the value that it remembers whatever it was before which i understand that that’s yeah yeah yeah so that’s the common use for it and that’s what i thought that you wanted to use but basically what you
want is that even the first try if you say true hereit would actually allow you to close it but the next time you call it it should be false by default right so it should be false yeah that way i don’t have to pass a parameter to it but if i do that right right yeah i understand exactly what what you mean in that case yeah but basically yesso not two things just to kind of like wrap up if you you would need a static variable right so in any case that is for you to be able to take a look at it later on
okay so that variable but again i i am torn on this because when you go ahead and call the the close command that that variable it’s not the same as the one in the function so let’s go ahead and do a message box right here yeah right i would say is be because i haven’t relaunched the thing it still is going to have the initial value the problem here is the thread who called that the the thread that calls this yeahthis yeah this label is not the same as the function now this variable exists within the
function so basically your idea of the global variable might be the correct one because you’re using actually a label instead of a function that’s why yeah and like i said that’s what i ended up having i got it to work but i didn’t understand why i had to do what i did right now so so in this case i think the global keyword would be that so if we if we try it right now if you if you go ahead and right so this is that’s a one all right right so let’s just remove one of the calls right now hold on
yeah where is that zero coming from yeah because of the because sorry yeah right so so the second call right here it’s final one no no no so we just want to have one call so we just want one call now right so we have a one right now so it is saved as a one but when you try to close it oh so hold ondid it right it’s still a one yeah right oh okay so it is still this is interesting yeah so so what i didn’t do was like you said i had them on the same line when i tried this static right the same line is the part that was actually
not making it work but it is interesting for me that even though this is a different thread yeah that it could still access a variable that belongs to this function that was something that i was not expecting at this moment i was expecting that probably the global keyword would be more suited for this but it seems to me that it actually works on that case had i restarted it we ran the thing from scratch it would have stopped it we would have overwritten it you know yes yes it would so yeah that was really interesting but but
basically this is one thing so static variables the only thing that should be on the static and global keywords is the initial value of it okay okay because that is read before everything starts even even before the script starts and basically you cannot put kind of like a parameter on there because at the beginning the script doesn’t have anything for that parameter it’s going to be blank right right that’s the reason why it doesn’t work but then if you want to pass a parameter to a static or go variable then you would
have to actually put it on its own line outside of the static keyword and then that is going to work i remember i was doing some stuff with the page here that we were doing an object like a http request and he’s like hey let’s put this inside of this function it make it static and so we’re not recreating that object every time so yes i usually thought of it as keeping the value so when i come back to it like if i want to do a counter or something it’ll increment that’s exactly that’s exactly right but
when he did it that way it totaled i’m like oh okay it’s not just keeping the data that value it can be keeping the instance of that object whatever yeah whatever you put in there the first time it’s gonna stay thereunless you change it during the course now this is this is one of one of the most common ways that i use static variables is when i do a function that does kind of like recursive recursion is that the function called itself now usually what you want to do in this kind of functions is that you want to keep track on which
level you’re in right now the static variable is very good at keeping which level because every time you go down a level you update the value of the static variable so call it level and every time you call the function itself you just go down one level you want to keep track of that the static variable is very good for that and whenever you go out you decrease the amount of the level right so you go down in you go in one that you increase the value you go out one you decrease the value and that static variable keeps track of
which level you’re in right so that’s the most common way that you could use static variables in functions but that what you’re doing right now is another way like i i passed the parameter i want to keep track of what that parameter wasbutthis thisline right here if it is not an if statement what is gonna happen is that every time you call the function is gonna kind of like replace the static variable so there is no point of having a static variable in our case it does it does have the purpose of
keeping track for us to use it down here on the label but as you are replacing it on the second call then that is going to be false automatically so yeah yeah cool awesome well thank you man that was really interesting yeah it is it is kind of like one of the most confusing things about functionswhy can’t i make a parameter static that’s kind of like i would label it how can i make a parameter well you can’t those are very special variables and you cannot make them either global orthe the way for making it global
though because there is a way of making them global is label them by ref yes right so if you make it by ref you are implicitly saying that that is a global variable that whatever changes you make down the down there at the bottom is going to affect whatever variable it is referring to the top but if you do not use biref then that is a local variable and yeah that’s that’s basically yeah that actually that’s the way that i learned the by ref like as soon as i figured out like by ref means global then that’s the only way
for you to grab a parameter and make it global you cannot make it down here on the on the line how you try it you try to make global exit the app that that’s not gonna work that’s what happens very cool bye thanks for watching that video and if you’re not aware of it we actually have a great intro to AutoHotkey course on this url up here it will give you a coupon code to use for it and i highly recommend you work through it if you just watch this video it’s probably the right place for you to
start and on the bottom here i have a couple examples of it helps you AutoHotkey is such a vast topic it’s really confusing on where you should start and what you should learn and there is no real write path right it depends what you’re wanting to learn but having the course to work through really helps you stay focused by paying for it you actually you’re more likely to do it and there’s a money-back guarantee so what do you want there’s over five hours of content in this course i think it’s a great intro to auto
hockey course so go for

Comments are closed.