Make var in Class.Method1() accessible for Class.Method2()

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Make var in Class.Method1() accessible for Class.Method2()

16 Dec 2013, 06:49

For example:

Code: Select all

Class phpBB
{
	Login(url, user, pwd) {
		static ForumUrl := "url"
		; Login ...
	}

	NewTopic(Title, Content) {
		MsgBox, % This.Login().ForumUrl "/posting.php?mode=post&f=5"
		; Post new topic ...
	}
}

phpBB.Login("http://ahkscript.org/boards", "u", "*")
phpBB.NewTopic("title", "content")
Return
How can I save the url in Login(), and retrieve the url in NewTopic(), the This.Login().ForumUrl is incorrect.

==========================================================

Currently I'm using something like global url in every methods, e.g.:

Code: Select all

Class test
{
	m1() {
		global url
	}

	m2() {
		global url
	}

	; ...
}
==========================================================

And I can't code like this, because the url is dynamic.

Code: Select all

Class test
{
	static url := url
}
Last edited by tmplinshi on 16 Dec 2013, 08:18, edited 1 time in total.
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: Retrieve variable in Class.Method()

16 Dec 2013, 07:35

You were very close with the static assignment
Try something like this

Code: Select all

Class phpBB
{
    Login(url, user, pwd) {
        static ForumUrl := "url"
        ; Login ...
        return url
    }

    NewTopic(Title, Content) {
        MsgBox, % This.Login().ForumUrl "/posting.php?mode=post&f=5"
        ; Post new topic ...
    }
}

url := phpBB.Login("http://ahkscript.org/boards", "u", "*")

msgbox % url

phpBB.NewTopic("title", "content")
Return
htms
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Retrieve variable in Class.Method()

16 Dec 2013, 07:45

Thanks for the quick reply, TLM.
However, that's not I'm trying to do. I want the NewTopic() to retrieve some variable in Login().
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: Retrieve variable in Class.Method()

16 Dec 2013, 08:18

sorry about that, I misread the question.

Code: Select all

Class phpBB
{
    Login(url, user, pwd) {
        static ForumUrl := "url"
        ; Login ...
        this.url := url
    }

    NewTopic(Title, Content) {
        MsgBox, % this.url "/posting.php?mode=post&f=5"
        ; Post new topic ...
    }
}

phpBB.Login("http://ahkscript.org/boards", "u", "*")
phpBB.NewTopic("title", "content")
Return
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Make var in Class.Method1() accessible for Class.Method2

16 Dec 2013, 08:23

Cool, Thanks a lot!
Sorry for my poor english. I can't describes this question easily.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998, mikeyww, ShatterCoder and 128 guests