1

Тема: AHK: сохранение глобального массива

Имеется скрипт в который подключается второй скрипт с классом Initializator. В основном файле прописывается строка после пдключения init := new Initializator(), после создается пустой глобальный массив global Binds := []. После всех этих действий идет вызов одной из функций класса init.initBinds() который обращается к функциям из этого же класса (в спойлере код файла с классом).

+ открыть спойлер

class Initializator
{		
	initStrings() {
		j := 0
		Loop % NumTabs * 10
		{
			j++
			i := 0
			Loop, % Bind[4, %A_Index%]
			{
				i++
				
				IniRead, String, Profiles\%Profile%\Hotkeys\Hotkey%A_Index%.mbmf, Sting%i%, Text
				Bind[1,j, i] := String
			}
		}
	}
	initWaitings() {
		j := 0
		Loop % NumTabs * 10
		{
			j++
			i := 0
			Loop, % Bind[4, %A_Index%]
			{
				i++
				IniRead, Time, Profiles\%Profile%\Hotkeys\Hotkey%A_Index%.mbmf, Sting%i%, Wait
				Bind[2,j, i] := Time
			}
		}
	}
	initPressEnters() {
		j := 0
		Loop % NumTabs * 10
		{
			j++
			i := 0
			Loop, % Bind[4, %A_Index%]
			{
				i++
				IniRead, Enters, Profiles\%Profile%\Hotkeys\Hotkey%A_Index%.mbmf, Sting%i%, TEnter
				Bind[3,j, i] := Enters
			}
		}
	}
	initNumberStrings() {
		Loop % NumTabs * 10
		{
			IniRead, NumStrings, Profiles\%Profile%\Hotkeys\Hotkey%A_Index%.mbmf, Main, NumStrings, 0
			Bind[4,%A_Index%] := NumStrings
		}
	}
	initHotKeys() {
		Loop % NumTabs * 10
		{
			IniRead, HKey, Profiles\%Profile%\Hotkeys\Hotkey%A_Index%.mbmf, Main, HKey, "none"
			Bind[5,%A_Index%] := HKey
		}
	}
	initIsFlooders() {
		Loop % NumTabs * 10
		{
			IniRead, Flooder, Profiles\%Profile%\Hotkeys\Hotkey%A_Index%.mbmf, Main, Flooder, "false"
			Bind[6,%A_Index%] := Flooder
		}
	}
	initTypeSends() {
		Loop % NumTabs * 10
		{
			IniRead, SendType, Profiles\%Profile%\Hotkeys\Hotkey%A_Index%.mbmf, Main, Type, "false"
			Bind[7,%A_Index%] := SendType
		}
	}
	initDefWaitings() {
		Loop % NumTabs * 10
		{
			IniRead, DWait, Profiles\%Profile%\Hotkeys\Hotkey%A_Index%.mbmf, Main, DefWaiting
			Bind[8,A_Index] := DWait
		}
	}
	initProfile() {
		msg := new Message()
		IfExist, Profiles/%Profile%/Settings.mbmf
		{
			IniRead, NumTabs, Profiles\%Profile%\Settings.mbmf, Main, NumTabs, 2
			IniRead, HkeyReload, Profiles\%Profile%\Settings.mbmf, Main, HKeyReload
			IniRead, HkeyPause, Profiles\%Profile%\Settings.mbmf, Main, HKeyPause
			IniRead, AutoUpdate, Profiles\%Profile%\Settings.mbmf, Main, AutoUpdate, "true"
			IniRead, UpdNotification, Profiles\%Profile%\Settings.mbmf, Main, UpdNotific, "true"
			IniRead, TrayLaunch, Profiles\%Profile%\Settings.mbmf, Main, TrayLaunch, "false"
		} else {
			msg.Info("Новый профиль настраивается, пожалуйста подождите", 3)
			FileCreateDir, %A_ScriptDir%\Profiles\%Profile%
			FileCreateDir, %A_ScriptDir%\Profiles\%Profile%\Hotkeys
			IniWrite, 2, Profiles\%Profile%\Settings.mbmf, Main, NumTabs
			IniWrite, none, Profiles\%Profile%\Settings.mbmf, Main, HKeyReload
			IniWrite, none, Profiles\%Profile%\Settings.mbmf, Main, HKeyPause
			IniWrite, true, Profiles\%Profile%\Settings.mbmf, Main, AutoUpdate
			IniWrite, true, Profiles\%Profile%\Settings.mbmf, Main, UpdNotific
			IniWrite, false, Profiles\%Profile%\Settings.mbmf, Main, TrayLaunch
			NumTabs := 2
			HKeyReload := "none"
			HKeyPause := "none"
			AutoUpdate := "true"
			UpdNotific := "true"
			TrayLaunch := "false"
		}
		Sys[1] := HkeyReload
		Sys[2] := HkeyPause
	}
	initSys() {
		IfExist,  Settings.mbmf
		{
			IniRead, Skin, Settings.mbmf, Main, Skin, Default
			IniRead, Profile, Settings.mbmf, Main, Profile, Default
		} else {
			IniWrite, Default, Settings.mbmf, Main, Skin
			IniWrite, Default, Settings.mbmf, Main, Profile
			IniWrite, %ID%, Settings.mbmf, Main, Key
			Skin := "Default"
			Profile := "Default"
		}
	}
	ActivateHotKeys() {
		j := 0
		Loop % NumTabs * 10
		{
			j++
			i := 0
			Loop, % Bind[4, A_Index]
			{
				i++
				Bind[2,j, i] := Time
			}
		}
	}
	initBinds() {
		this.initHotKeys()
		this.initNumberStrings()
		this.initStrings()
		this.initWaitings()
		this.initPressEnters()
		this.initIsFlooders()
		this.initTypeSends()
		this.initDefWaitings()
	}
}

При заполнении массива через классовые функции он не сохраняет все данные в массиве. В чем может быть проблема? Если у меня грубая ошибка с классами то где я мог ошибиться?

2

Re: AHK: сохранение глобального массива

У вас в каждом методе идёт:

Loop % NumTabs * 10

А чему равна эта NumTabs?

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

3

Re: AHK: сохранение глобального массива

teadrinker NumTabs изменяется в ini файле, в данный момент она равна 3.

4

Re: AHK: сохранение глобального массива

А метод класса-то откуда об этом узнает?
Например, у вас есть такой метод:

	initHotKeys() {
		Loop % NumTabs * 10
		{
			IniRead, HKey, Profiles\%Profile%\Hotkeys\Hotkey%A_Index%.mbmf, Main, HKey, "none"
			Bind[5,%A_Index%] := HKey
		}
	}

В нём NumTabs не задана, она там локальная.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

5

Re: AHK: сохранение глобального массива

teadrinker,Это гобальная переменная которая инициализируется так же в этом классе из ini. Вот все глобальные переменные:


global ID := GetMyIP()
global Version := "2.6"
global Author := "McFree"
global NumTabs
global Profile
global Skin
global AutoUpdate
global UpdNotification
global TrayLaunch
global ThisBind

global THK1
global THK2
global THK1
global CHK
global WHK
global SHK
global AddTime
global AddText
global HKReload
global HKPause
global ColTabs
global Autoupdat
global Answer
global TrayLoad

global Sys := []
global Bind := []	

6

Re: AHK: сохранение глобального массива

Ну так я ж не экстрасенс, я просто указал на ошибку в коде на основе тех данных, что вы представили. Может оказаться, что вы ещё что-нибудь скрыли, как я могу оценить правильность кода?

Вообще, чтоб получить внятный ответ, в вопросе нужно представить минимальный код, который любой может запустить, и который чётко демонстрирует проблему. Научившись составлять такой код, вы увидите, что многие вопросы отпадут сами собой.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

7 (изменено: McFree, 2016-08-24 23:01:18)

Re: AHK: сохранение глобального массива

teadrinker тогда сделаю код минимальным:

Класс инициализации в файле initManager:

+ открыть спойлер

class Initializator
{
	initStrings() {
		j := 0
		Loop % NumTabs * 10
		{
			j++
			i := 0
			Loop, % Bind[4, %A_Index%]
			{
				i++
				
				IniRead, String, Profiles\%Profile%\Hotkeys\Hotkey%A_Index%.mbmf, Sting%i%, Text
				Bind[1,j, i] := String
			}
		}
	}
	initProfile() {
		msg := new Message()
		IfExist, Profiles/%Profile%/Settings.mbmf
		{
			IniRead, NumTabs, Profiles\%Profile%\Settings.mbmf, Main, NumTabs, 2
			IniRead, HkeyReload, Profiles\%Profile%\Settings.mbmf, Main, HKeyReload
			IniRead, HkeyPause, Profiles\%Profile%\Settings.mbmf, Main, HKeyPause
			IniRead, AutoUpdate, Profiles\%Profile%\Settings.mbmf, Main, AutoUpdate, "true"
			IniRead, UpdNotification, Profiles\%Profile%\Settings.mbmf, Main, UpdNotific, "true"
			IniRead, TrayLaunch, Profiles\%Profile%\Settings.mbmf, Main, TrayLaunch, "false"
		} else {
			msg.Info("Новый профиль настраивается, пожалуйста подождите", 3)
			FileCreateDir, %A_ScriptDir%\Profiles\%Profile%
			FileCreateDir, %A_ScriptDir%\Profiles\%Profile%\Hotkeys
			IniWrite, 2, Profiles\%Profile%\Settings.mbmf, Main, NumTabs
			IniWrite, none, Profiles\%Profile%\Settings.mbmf, Main, HKeyReload
			IniWrite, none, Profiles\%Profile%\Settings.mbmf, Main, HKeyPause
			IniWrite, true, Profiles\%Profile%\Settings.mbmf, Main, AutoUpdate
			IniWrite, true, Profiles\%Profile%\Settings.mbmf, Main, UpdNotific
			IniWrite, false, Profiles\%Profile%\Settings.mbmf, Main, TrayLaunch
			NumTabs := 2
			HKeyReload := "none"
			HKeyPause := "none"
			AutoUpdate := "true"
			UpdNotific := "true"
			TrayLaunch := "false"
		}
		Sys[1] := HkeyReload
		Sys[2] := HkeyPause
	}
	initSys() {
		IfExist,  Settings.mbmf
		{
			IniRead, Skin, Settings.mbmf, Main, Skin, Default
			IniRead, Profile, Settings.mbmf, Main, Profile, Default
		} else {
			IniWrite, Default, Settings.mbmf, Main, Skin
			IniWrite, Default, Settings.mbmf, Main, Profile
			IniWrite, %ID%, Settings.mbmf, Main, Key
			Skin := "Default"
			Profile := "Default"
		}
	}
	initBinds() {
		this.initStrings()
	}
}

Гланый файл скрипта:

+ открыть спойлер

#Persistent 
#SingleInstance force
#MaxThreadsPerHotkey 3
#MaxThreads 7
SendMessage, 0x50,, 0x4190419,, A
;
;		includes
;
#Include samp_udf.ahk
#include InitManager.ahk
;
;		Objects
;
init := new Initializator()

;
;		globals
;
global ID := GetMyIP()
global NumTabs
global Profile
global Skin
global ThisBind

global HKReload
global HKPause
global ColTabs
global Autoupdat
global Answer
global TrayLoad

global Sys := []
global Bind := []	

;
;		initializations
;
init.initSys()
init.initProfile()
init.initBinds()
return

Во время исполнения функции init.initBinds() которая использует функцию из класса из своего класса initStrings() массив забивается значениями из ini файла. После работы с функциями класса Initializator массив все равно остается пустым. Во время использования самой функции initStrings() в массиве имеются значения, но после работы функции весь массив опять становится пустым.

Вроде как сделал более краткий код

8

Re: AHK: сохранение глобального массива

Всё, что касается игр, не пишите в ветке AHK.
Нет, это не то, что я имел в виду. Код не короткий, для демонстрации только проблемы там много лишнего. Кроме того, я не могу его запустить — у меня нет ни samp_udf.ahk, ни GetMyIP(), ни вашего ini-файла.
Посоветовать могу в каждом методе проверять какие значения переменным установлены через MsgBox.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

9

Re: AHK: сохранение глобального массива

teadrinker, прошу прощения, прикрепил к ответу файлы для работы с этим скриптом

Post's attachments

samp_udf.ahk 184.99 kb, 3 downloads since 2016-08-25 

You don't have the permssions to download the attachments of this post.

10 (изменено: McFree, 2016-08-26 00:59:13)

Re: AHK: сохранение глобального массива

McFree пишет:

teadrinker, прошу прощения, прикрепил к ответу файлы для работы с этим скриптом

Post's attachments

API.dll 488 kb, 2 downloads since 2016-08-25 

You don't have the permssions to download the attachments of this post.

11

Re: AHK: сохранение глобального массива

McFree пишет:
Loop, % Bind[4, %A_Index%]

Не знаю, может это не единственная ошибка, но знаки процента вокруг A_Index не нужны. McFree, вам, скорее всего, рановато с классами, сначала нужно с простыми вещами разобраться.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

12

Re: AHK: сохранение глобального массива

teadrinker, я дурак и по привычке ставлю пробелы после запятой, многомерный массив не должен хранить в индексе запятую. Писал под вечер так что не судите строго.