Jump to content

Declaring variable in a function for use in sub-functions


Recommended Posts

Lets say we've got nested functions.

_Alpha()

Func _Alpha()
  $a = 1
  _Bravo()
EndFunc

  Func _Bravo()
     msgbox(0,"",$a)
    _Charlie()
  EndFunc

    Func _Charlie()
      msgbox(0,"",$a)
    EndFunc

As far as I know, the only way to get the above msgbox() in both _Bravo() and _Charlie() to work properly, either $a = 1 must be declared as Global scope, or $a must be passed to _Bravo() and then passed again to _Charlie(). Is there another way?

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

You can use global variables or submit a parameter to the function:

_Alpha()

Func _Alpha()
  Local $a = 1
  _Bravo($a)
EndFunc

  Func _Bravo($a)
     msgbox(0,"",$a)
    _Charlie($a)
  EndFunc

    Func _Charlie($a)
      msgbox(0,"",$a)
    EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Is there another way?

Maybe Herez one

EnvSet('a','nothing')
_Alpha()
Func _Alpha()
  _Bravo()
EndFunc
  Func _Bravo()
     msgbox(0,"",EnvGet('a'))
    _Charlie()
  EndFunc
    Func _Charlie()
      msgbox(0,"",EnvGet('a'))
    EndFunc

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...