Jump to content

Recommended Posts

Posted

So, I'm trying to make this autoit script, and there's a function and stuff, but I can't write a function, inside a function! It's just not working. :(

Like;

Func Function_A($para1)
    Local $thing = 1
    
    Func Function_B()
        ;Stuff here
    EndFunc
    
    If Function_B($thing) Then
        ;Stuff
    Else
        ;Stuff
    EndIf
    
EndFunc

; Something like that.

I'm either doing it wrong, or I can't do it in autoit.

Anyway, help me please!

Posted

What you need to do is something like the following.

Func Function_A($para1)
    Local $thing = 1
    
    $result = Function_B()
    If $result = $something Then
        ;Stuff
    Else
        ;Stuff
    EndIf
    
EndFunc

Func Function_B()
    ;Stuff here
EndFunc

You don't nest a function within another function, you just make a call to it. All functions need to exist in the root of your code, not within other identities. An #Include file is the one exception.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

Actually that did used to be possible, in the days of when v3.3.10.0 was being developed. It was removed as it was felt it was out of scope of what the language was. Please don't request it be added to the language again, even though it is pretty neat with regards to encapsulating relevant functions together in a sort of namespace.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

That's a surprise.  So there is a possibility that one day we might get this feature!  (Only if we act right!)

That being said.  AutoIt is no longer the roll out machine imaging scripting language it was originally designed to be.  It's now a full fledged scripting language with amazing new features.  Why should it be out of scope to incorporate features which contribute to a deeper level of script structuring?  I wonder why is it that some new features are allowed, and yet others are rejected as being out of scope?  What then is the scope of AutoIt?  Yes, the easy answer is, "Whatever Jon decides."  You wouldn't be wrong.

Posted
  On 7/10/2015 at 1:16 PM, jaberwacky said:

 wonder why is it that some new features are allowed, and yet others are rejected as being out of scope?  What then is the scope of AutoIt?  Yes, the easy answer is, "Whatever Jon decides."  You wouldn't be wrong.

You answered your own question. But as I see it, the scope of AutoIt for now is to stay true to its roots of being based on BASIC (procedural era).

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 7/10/2015 at 1:21 PM, UEZ said:

I saw that already (afair in JS) but what is the purpose to have a function within a function?

Otherwise known as closures. Basically you can do some pretty awesome stuff, like encapsulating "things" together in a single function. My favourite pattern, is the Revealing Module Pattern, which relies alot on closures

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)
  On 7/10/2015 at 1:21 PM, UEZ said:

I saw that already (afair in JS) but what is the purpose to have a function within a function?

Well, I think it goes back to what guinness said about namespaces.  I would use it with an eye toward information hiding -- which isn't OOP btw.  OOP is inherently information hiding, but information hiding isn't necessarily OOP.)

 

Edit: what guinness said. ^^^^^

Edited by jaberwacky
Posted

Thanks guinness & jaberwacky for your quick reply. I see that it might make a sense / nice to have in OOP.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
  On 7/10/2015 at 1:31 PM, jaberwacky said:

Edit: what guinness said. ^^^^^

Well the "encapsulating things" is a little sloppy, but glad you understood my point =)

Posted this back in April >> https://www.autoitscript.com/forum/topic/169919-first-version-of-jquery-annotated-by-john-resig-9-years-of-jquery/?do=findComment&comment=1242913

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
×
×
  • Create New...