Send variables with ByRef from a nested function to another function? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Send variables with ByRef from a nested function to another function?

Post by Krd » 21 Feb 2023, 11:27

Hey again.

Further progress here converting my files to v2 :)

I am stuck here as i want to avoid global variables as much as I can. Is this possible:

Code: Select all

F1::function_Main()

function_Main()
{
; click click
;Send send
function_1()
; click click
;Send send
function_2()
; click click
;Send send
}


function_1()
{
MyVar := "I am fucntion one"
	function_Nested(&MyVar)
        {
			MyVar ;???
        }
}

function_2()
{
function_Nested(&MyVar) ;????
MsgBox MyVar
}
How do I make the nested fucntion to steal the MyVar variable and be able to read that from function_2?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Send variables with ByRef from a nested function to another function?

Post by swagfag » 25 Feb 2023, 17:08

the question is nonsense and so is the code and the comments, so i have no idea what ure asking nor what ure trying to do

read the entire chapter on Functions in the docs. maybe ull get some ideas

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Send variables with ByRef from a nested function to another function?

Post by Krd » 26 Feb 2023, 13:00

thanks
.

for just as

,nonsense replay

whoops
Posts: 10
Joined: 12 May 2023, 18:51

Re: Send variables with ByRef from a nested function to another function?

Post by whoops » 12 May 2023, 18:59

Apologies in advance for the necro, but I thought it may come in handy for anybody else looking around. After all, I ran across it!

Ignore the salty response to the OP, clearly he was just having a bad day.

Just to give this post some finality, for anybody still moving over to v2 and the ability to use nested functions and seeking to use ByRef wherever possible (saves memory and coding effort)

Code: Select all

test(&value)
{
	ErrorLevel := test2(&value)
	return 1
}

test2(&value)
{
	value := "success"
	return 1
}

ErrorLevel := test(&value)
MsgBox(value)
This nested function returns "success" to the MsgBox at the top level of the code from inside the nested function via ByRef.

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Send variables with ByRef from a nested function to another function?  Topic is solved

Post by boiler » 12 May 2023, 19:08

That does demonstrate ByRef parameters, but not nested functions. That’s a function calling another function, but not a nested one. To be nested, one function would be inside another one.

Code: Select all

test(&value) {
	test2(&value)

	test2(&val) {
		val := "success"
	}
}

test(&MyValue)
MsgBox MyValue

whoops
Posts: 10
Joined: 12 May 2023, 18:51

Re: Send variables with ByRef from a nested function to another function?

Post by whoops » 02 Jun 2023, 10:45

fair, and thank you for the clarification.
i'm far from an expert, but i knew it was possible and wanted to put a happy ending to this thread.

thank you for providing that. :-D

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Send variables with ByRef from a nested function to another function?

Post by Krd » 07 Jun 2023, 02:35

Come on, boiler! You could have provided this replay months ago! Don't tell me you didn't know how. :)

It's too late now to change thousands of lines of logic, but may come handy later on :D

Thank you!

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Send variables with ByRef from a nested function to another function?

Post by boiler » 07 Jun 2023, 04:12

Krd wrote: Come on, boiler! You could have provided this replay months ago! Don't tell me you didn't know how. :)
No, I don’t know how to reply months earlier to a post that was made 9 minutes before mine.


Post Reply

Return to “Ask for Help (v2)”