Problem with global variable

All about the macro plugin can be found in this forum. This forum is intended for the macro plugin only.

Moderator: Moderators

qualitybot
Noob
Noob
Posts: 5
Joined: 29 Jan 2014, 07:05
Noob?: Yes

Problem with global variable

#1 Post by qualitybot »

Hi, I having a problem on declaring global variable so I test some few macro.

Code: Select all

$var3 = test

macro test {
	$var = test
	$var2 = test2
	log $var
}

macro test2 {
	log $var2
}

macro test3 {
	log $var3
}
Here is the result.

1. If I call the macro "test" it will work.
2. If I call the macro "test2" after I call the macro "test" it will work.
3. If I call the macro "test2" before I call the macro "test" it will return a null value.
4. If I call the macro "test3" it will return a null value.

So my problem now is what is the best way to use global variable? I'am making a macro that will used value from a config file and it will be a hustle if I call @cofig every time I need this value. So what is the correct way to use global variable in macro? thanks
iMikeLance
Moderators
Moderators
Posts: 208
Joined: 01 Feb 2010, 17:37
Noob?: No
Location: Brazil - MG

Re: Problem with global variable

#2 Post by iMikeLance »

You can achieve this by creating an automacro, no conditions, just run-once 1. This automacro will trigger right after login and then you can set your "global variables".
Like this:

Code: Select all

automacro globals {
run-once 1
call {
$myglobal = value
}
}
You can't create variables outside of macros or subroutines in macro plugin.

PS: ALL variables are globals in this plugin.
rocknroll
Been there done that!
Been there done that!
Posts: 118
Joined: 19 Sep 2011, 07:30
Noob?: Yes

Re: Problem with global variable

#3 Post by rocknroll »

or you can creating an automacro that triggered when in game state

automacro first {
hook in_game
exclusive 1
call {
$var = hmm
}
}
Sorry, my english is very bad !