InGame v2.0

Post gaming related scripts
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

[a108] Class Debug

15 Mar 2020, 03:52

As

Code: Select all

class Debug {
...
} ;------------------------------------------------------------------------
Debug:= ''
Will kill next debugging.

Code: Select all

class Proto {
	File:= ''
	out(cond, mess, ifcond:= '', ifnotcond:= '') {
		OutputDebug(output:= A_ScriptName ':' mess ':' String(cond) ':' (cond? ifcond: ifnotcond)) ;use debugview.exe
		try this.File.WriteLine(output) this.File.Read(0)
		return cond
}	}
Debug() {
	static __:= Proto.new()
	return __
}
And usage:

Code: Select all

var:= 1
Debug().File:= FileOpen('123.txt', 'w')
Debug().out(1, 'Start Debug')
if Debug().out(var == 1, 'If var == 1', 'true', 'false')
	 Debug().out(1, 'var is true  => then')
else Debug().out(1, 'var is false => else')

Debug().File:= ''
if Debug().out(var == 2, 'If var == 2', 'true', 'false')
	 Debug().out(1, 'var is true  => then')
else Debug().out(1, 'var is false => else')

Debug().File:= FileOpen('123.txt', 'a')
if Debug().out(var == 3, 'If var == 3', 'true', 'false')
	 Debug().out(1, 'var is true  => then')
else Debug().out(1, 'var is false => else')
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

DefineClass shorthand

20 Mar 2020, 09:21

Inspired by Helgef.
AHK no method to be created specific class object inside function:

Code: Select all

class myclass {
}
...
myclass:= '' ;make myclass undefined
...
myfunction() {
	instance:= myclass.new() ;possible exception
	...
}
In other hand in AHK is not possible function to contain class definition and there no shorthand way to be created method inside object.
The sollution:

Code: Select all

;DefineClass function
;	Function alow creating | override | adding new properties | methods
;	to given object
;	Parameters:
;		clas: (object) existing instance | properties
;		what: (object) containing new | override methods
DefineClass(ByRef clas, what) { ;inspired by Helgef --------------------------
	for name, meth in what.OwnProps()
		clas.DefineMethod(name, meth)
	return clas	
} ;----------------------------------------------------------------------------
Usage: with example

Code: Select all

;let we must create object like defined below
class proto {
	p1:= 'prop 1'
	p2:= 'prop 2'
	m1() => 'meth 1'
	m2() => 'meth 2'
}

Code: Select all

pr:= DefineClass({  p1: 'prop 1'	;object
				  , p2: 'prop 2'	;properties -----	
				 }		
				,{	m1: (*)=>'meth 1'	;object
				  , m2: (*)=>'meth 2'	;methods --------	
				 })
That is equivalent to:

Code: Select all

pr:= proto.new()
And now any function can create own class:

Code: Select all

myfunction() {
	instance:= DefineClass({p1: 'prop 1', p2: 'prop 2'}, {m1: (*)=>'meth 1', m2: (*)=>'meth 2'})
	...
}
AHKv2.0 alpha forever.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 10 guests