Help in understand byRef Functions

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

Help in understand byRef Functions

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

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: 1946
Joined: 30 Sep 2013, 22:25

Re: Help in understand byRef Functions

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

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Bing [Bot], Descolada, Draken, Sacho and 35 guests