Help in understand byRef Functions

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
jsong55
Posts: 258
Joined: 30 Mar 2021, 22:02

Help in understand byRef Functions

Post by jsong55 » 15 May 2023, 23:04

I need to constantly work on 2 nested maps

Code: Select all

MapOfReValueSGT, MapOfReValueOthers
I first initialize them here

Code: Select all

MapOfReValueOthers := Map()
MapOfReValueSGT:=Map()
Loop 3
    MapOfReValueOthers[A_Index] := Map()
Loop 3
    MapOfReValueSGT[A_Index] := Map()
Then I pass them into a function that's been defined

Code: Select all

Mtd2Clicked(*) ; from a gui button
{
    Mtd2Fn(&MapOfReValueOthers,&MapOfReValueSGT)
}
The function is defined here

Code: Select all

Mtd2Fn(&MapOfReValueOthers,&MapOfReValueSGT)
{
; some code in between that uses both Map values
}
Problem is when I debug within the function Mtd2Fn it says the maps are not intialized. When I debug the step outside at Mtd2Clicked - they are fine, they are global and initialized.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Help in understand byRef Functions

Post by swagfag » 16 May 2023, 00:00

ur issues have less(in fact, nothing) to do with ByRef and everything to do with the way ur code is structured/scoping

post the full nonworking code, then i can tell u what u did wrong
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Help in understand byRef Functions

Post by FanaticGuru » 16 May 2023, 22:43

jsong55 wrote:
15 May 2023, 23:04

Code: Select all

Mtd2Clicked(*) ; from a gui button
{
    Mtd2Fn(&MapOfReValueOthers,&MapOfReValueSGT)
}
Problem is when I debug within the function Mtd2Fn it says the maps are not intialized. When I debug the step outside at Mtd2Clicked - they are fine, they are global and initialized.

Probably not really global but read only. Need to explicitly make them global in Mtd2Clicked.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Post Reply

Return to “Ask for Help (v2)”