A few beginner questions
Posted: Mon May 06, 2019 12:29 pm
I am trying to teach myself HollyWood and start with looking at some of the examples and in the manual, but I still have a few things I wonder about.
Looking at CircleText.hws that have the "Repeat - waitevent - forever" loop.
After reading a bit in the docs, I think I get a clue on how that works.
The program will stay in this loop, but will be triggered by the event set by SetInterval, so it goes through the p_mainloop once every 40ms.
So far so good.
Reading further, the doc say that SetInterval() always must be used with waitevent. And Waitevent should only be present once in every script.
The docs for SetIntervals also states that you can install as many intervals as you want in your script.
Then I asume that waitevent will need to use the identifier to know which event it is waiting for.
But in CircleText.hws example the SetInterval is given the ID 1, but the waitevent is left without an argument. I find that a bit confusing.
I read that the the exclamation mark (!) can be used in variable names. And I notice that it is used in some example scripts, like in the CircleText.hws.
I was confused by this, until I read the manual that it is simply a part of the variable name. But I wonde why is it used in that example on some variables and not on others. Did the author have some reason for this, to make certian variables stand out on a way, or is it just a coincidence?
gosub vs functions (Local vs global variables)
I did study some AmiBlitz earlier, and I noticed that it was considered bad programming practice to goto and gosub. One should use statements or functions instead. One of arguments for this was that then the variables was local and would not interfere with your variables in the main loop. One could get a variable to be global, but this was to be defined in each case.
In my case, I never got around to see the benefit of this. Since I wanted all my variables to be global, and therefore I found gosubs to be far easier to use (and understand).
How is this with HollyWood functions, are variables global for the program, or are they local for each function?
Looking at CircleText.hws that have the "Repeat - waitevent - forever" loop.
After reading a bit in the docs, I think I get a clue on how that works.
The program will stay in this loop, but will be triggered by the event set by SetInterval, so it goes through the p_mainloop once every 40ms.
So far so good.
Reading further, the doc say that SetInterval() always must be used with waitevent. And Waitevent should only be present once in every script.
The docs for SetIntervals also states that you can install as many intervals as you want in your script.
Then I asume that waitevent will need to use the identifier to know which event it is waiting for.
But in CircleText.hws example the SetInterval is given the ID 1, but the waitevent is left without an argument. I find that a bit confusing.
I read that the the exclamation mark (!) can be used in variable names. And I notice that it is used in some example scripts, like in the CircleText.hws.
I was confused by this, until I read the manual that it is simply a part of the variable name. But I wonde why is it used in that example on some variables and not on others. Did the author have some reason for this, to make certian variables stand out on a way, or is it just a coincidence?
gosub vs functions (Local vs global variables)
I did study some AmiBlitz earlier, and I noticed that it was considered bad programming practice to goto and gosub. One should use statements or functions instead. One of arguments for this was that then the variables was local and would not interfere with your variables in the main loop. One could get a variable to be global, but this was to be defined in each case.
In my case, I never got around to see the benefit of this. Since I wanted all my variables to be global, and therefore I found gosubs to be far easier to use (and understand).
How is this with HollyWood functions, are variables global for the program, or are they local for each function?