Simple number manipulation Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

16 Sep 2021, 17:39

swagfag wrote:
16 Sep 2021, 17:17
ur explanations are all over the place
this thing
contradicts
this other thing

and this
shows yet another wrong sequence
Well yes you’re comparing two different things. I said I edited and simplified everything now after learning the errors in the logic. The only thing which matters now is the latest image, and the principle that one can add as many sets of integers as they like as long as there are no duplicates to confuse things.
User avatar
boiler
Posts: 16709
Joined: 21 Dec 2014, 02:44

Re: Simple number manipulation

16 Sep 2021, 18:00

Still not consistent, so if you can’t write out the rules and you can’t write examples that are coherent, we can’t write the code.

Look at the first 3 examples in the first column of your last graphic. The first key press is R from the 3, 23 starting point for each of those cases. Yet in two of those cases, you say the first position moved to should be 5, but you say it should be 4 in the other.

Also, in the second column starting from 9, 90, you have two examples that start with R, L, but their first two outcomes are different (-, - in one case and -, 3 in the other).

It’s probably not hard to guess what you meant, but then it would be hard to prove to you the code is correct since the output wouldn’t always match your (flawed) examples, so your should first produce a correct set of examples.
User avatar
flyingDman
Posts: 2776
Joined: 29 Sep 2013, 19:01

Re: Simple number manipulation  Topic is solved

16 Sep 2021, 18:23

Concur with @boiler first statement: It would be very helpful (it would have been since the beginning, to be honest), if you would post the rule, rather than giving examples.
Let me try: "There are four lists consisting of unique pairs of integers; one list for each of the keyboard arrows (Left, Right, Up and, Down). A pair of integers is chosen as a starting point (=current pair). When the user pushes one of the 4 keys, the current pair becomes the one following the matching pair in the corresponding list. If no such pair is found the result is blank."
Because the rule involves the comparison of pairs of integers , I suggest that rather than using arrays, pairs be represented by strings.
This is my new attempt:

Code: Select all

Left  := ["6,27", "9,90","4,65", "3,23","58,105"]
Right := ["19,60","12,22","3,23","4,65"]
strt := "3,23"
left::
for x,y in Left
	if (y = strt)
		{
		z := x = Left.count() ? 0 : x
		strt := Left[z+1]
		rslt := strt
		break
	    	}
	else
		rslt := ""
tooltip, % ">" rslt "<"
return

right::
for x,y in Right
	if (y = strt)
		{
		z := x = Right.count() ? 0 : x
		strt := Right[z+1]
		rslt := strt
		break
	   	 }
	else
		rslt := ""
tooltip, % ">" rslt "<"
return
14.3 & 1.3.7
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Simple number manipulation

16 Sep 2021, 18:55

yeah these cases basically make no sense
image.png
image.png (50.88 KiB) Viewed 1145 times
all this effort for some dumb ass game probably...
might as well post a video showcasing the mechanic instead, if u cant explain it in abstract terms
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

16 Sep 2021, 23:06

flyingDman wrote:
16 Sep 2021, 18:23
Concur with @boiler first statement: It would be very helpful (it would have been since the beginning, to be honest), if you would post the rule, rather than giving examples.
Let me try: "There are four lists consisting of unique pairs of integers; one list for each of the keyboard arrows (Left, Right, Up and, Down). A pair of integers is chosen as a starting point (=current pair). When the user pushes one of the 4 keys, the current pair becomes the one following the matching pair in the corresponding list. If no such pair is found the result is blank."
Because the rule involves the comparison of pairs of integers , I suggest that rather than using arrays, pairs be represented by strings.
This is my new attempt:

Code: Select all

Left  := ["6,27", "9,90","4,65", "3,23","58,105"]
Right := ["19,60","12,22","3,23","4,65"]
strt := "3,23"
left::
for x,y in Left
	if (y = strt)
		{
		z := x = Left.count() ? 0 : x
		strt := Left[z+1]
		rslt := strt
		break
	    	}
	else
		rslt := ""
tooltip, % ">" rslt "<"
return

right::
for x,y in Right
	if (y = strt)
		{
		z := x = Right.count() ? 0 : x
		strt := Right[z+1]
		rslt := strt
		break
	   	 }
	else
		rslt := ""
tooltip, % ">" rslt "<"
return
This is it yes, and with additional regards to boiler, swagfag and others also, I will note how to describe such rules better, and genuinely thank you for the example commentary. Typically I am quite the verbose writer, and am sure my post history will astonish I, the author. An obvious flaw in my repertoire, I will endeavour to improve.

One issue, and this is not a plausible excuse, I know, is that my initial idea is often flawed, and I can only envision things as they begin to get constructed. An engineer's nightmare, this is why I am caged within other fields...
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

16 Sep 2021, 23:09

swagfag wrote:
16 Sep 2021, 18:55
all this effort for some dumb ass game probably...
This is cute, and the most amusing wake-up post! I haven't gamed since I was 13, unfortunately. Used to play AoE a lot!

No, rather this is for my financial software. I use it fund the three companies, one of which I'm finally able to turn into a charitable foundation here in the UK. I wake at 4.30am, so by 10/11pm I'm pretty stuffed if I say so myself, so I can only apologise for frustrating you. Thanks for the help:? though!

May I kindly ask if this is the best way to gain the separate integer values from 'strt'?

Code: Select all

ch := StrSplit(strt,",")
ch1 := ch.1
ch2 := ch.2
Msgbox start %strt% ch1 %ch1% ch2 %ch2%
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Simple number manipulation

17 Sep 2021, 16:26

(for left/right/up/down/enter/more buttons)
for arbitrary sequences/transitions/actions/hotkeys with duplicates and whatnot, ure better off with a state machine

Code: Select all

#NoEnv
#Warn ClassOverwrite

root := new State()
3_23 := new State("3_23") ; change as needed
9_90 := new State("9_90") ; change as needed
4_65 := new State("4_65") ; change as needed
53_3 := new State("53_3") ; change as needed
57_90 := new State("57_90") ; change as needed

; Which Hotkey pressed? | Current State | Next State
States := { Left: { (root): 3_23, (3_23): 9_90, (9_90): 4_65, (4_65): 3_23 }
          , Right: { (root): 3_23, (3_23): 53_3, (53_3): 57_90, (57_90): 3_23 } }

CurrentState := root

Left::
Right::
	MaybeNextState := States[A_ThisHotkey][CurrentState]
	if (MaybeNextState != "")
	{
		MaybeNextState.perform()
		CurrentState := MaybeNextState
	}
return

class State
{
	__New(data := "") { ; change as needed
		this.data := data ; change as needed
	}

	perform() {
		ToolTip % this.data ; change as needed
	}
}
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

18 Sep 2021, 18:15

swagfag wrote:
17 Sep 2021, 16:26
(for left/right/up/down/enter/more buttons)
for arbitrary sequences/transitions/actions/hotkeys with duplicates and whatnot, ure better off with a state machine
Thanks so much. For this, I suspect I need to study posts such as viewtopic.php?t=6033 and viewtopic.php?t=66792 ?

In the meantime, could I also ask for help (last one I promise) on splitting the sets of integers and then reversing the order? The closest I can find to this is to use StrSplit as flyingDman said it is classed a string, meaning we must first split and store as an array...

Code: Select all

Right := ["19,60","12,22","3,23","4,65"]
Would require

Code: Select all

strsplit(right," ")
But even then, what would we put into the " "s, if we want to have the same string structure as the output? I.e.

Code: Select all

 ["4,65","3,23","12,22","19,60"]
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Simple number manipulation

18 Sep 2021, 18:47

idk about that. at the very least ud have to know what a state machine is. implementations are aplenty. some use classes, some tables, some function pointers, some mix and match. thats for u to decide which one u like best
u can reverse (and sparse) arrays like so:

Code: Select all

Right := ["19,60","12,22","3,23","4,65"]
Right := reverse(Right)

reverse(Arr) {
	Reversed := []
	Reversed.SetCapacity(Arr.GetCapacity())

	Loop % len := Arr.Length()
		if Arr.HasKey(A_Index)
			Reversed[len - A_Index + 1] := Arr[A_Index]

	return Reversed
}
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

19 Sep 2021, 13:04

swagfag wrote:
18 Sep 2021, 18:47
idk about that. at the very least ud have to know what a state machine is. implementations are aplenty. some use classes, some tables, some function pointers, some mix and match. thats for u to decide which one u like best
u can reverse (and sparse) arrays like so:

Code: Select all

Right := ["19,60","12,22","3,23","4,65"]
Right := reverse(Right)

reverse(Arr) {
	Reversed := []
	Reversed.SetCapacity(Arr.GetCapacity())

	Loop % len := Arr.Length()
		if Arr.HasKey(A_Index)
			Reversed[len - A_Index + 1] := Arr[A_Index]

	return Reversed
}
Works a charm! If I wanted to print the reversed outcome as text, is it really as difficult as this https://stackoverflow.com/questions/46002967/how-do-i-print-an-array-in-autohotkey/46005037?
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

02 Oct 2021, 18:57

swagfag wrote:
17 Sep 2021, 16:26
(for left/right/up/down/enter/more buttons)
for arbitrary sequences/transitions/actions/hotkeys with duplicates and whatnot, ure better off with a state machine

Code: Select all

#NoEnv
#Warn ClassOverwrite

root := new State()
3_23 := new State("3_23") ; change as needed
9_90 := new State("9_90") ; change as needed
4_65 := new State("4_65") ; change as needed
53_3 := new State("53_3") ; change as needed
57_90 := new State("57_90") ; change as needed

; Which Hotkey pressed? | Current State | Next State
States := { Left: { (root): 3_23, (3_23): 9_90, (9_90): 4_65, (4_65): 3_23 }
          , Right: { (root): 3_23, (3_23): 53_3, (53_3): 57_90, (57_90): 3_23 } }

CurrentState := root

Left::
Right::
	MaybeNextState := States[A_ThisHotkey][CurrentState]
	if (MaybeNextState != "")
	{
		MaybeNextState.perform()
		CurrentState := MaybeNextState
	}
return

class State
{
	__New(data := "") { ; change as needed
		this.data := data ; change as needed
	}

	perform() {
		ToolTip % this.data ; change as needed
	}
}
Hi swagfag, it was my understanding that this use of classes would require a fair bit more typing (you will understand what I mean when you see the length below), and in two sections (in 'root := new State' as well as 'which hotkey pressed').

I had success enough with the first solution for the past two weeks, to even be able to expand the scope of my work. However, I ran into one of the many issues you were alluding to, namely 'expression being too large'.

If you could help me with a simple solution to rectify this, perhaps by joining more arrays together, it would help me the most. However, if we cannot, could you kindly help me with extracting the output from perform() above and adapting them into my 'sendchart' functionality below?:

Code: Select all

ch1:=1
ch2:=113
strt := "1,113"

ForLButtonNotHold := ["1,113","1,153","1,113","9,121","9,153","9,121","17,129","17,152","17,129","25,137","25,153","25,137","33,113","33,161","33,113","41,121","41,161","41,121","49,129","49,161","49,129","57,145","57,161","57,145","65,121","65,169","65,121","73,121","73,177","73,121","81,121","81,185","81,121","89,129","89,169","89,129","89,129","89,185","89,129","97,129","97,185","97,129","105,137","105,169","105,137","2,114","2,154","2,114","10,122","10,154","10,122","18,130","18,153","18,130","26,138","26,154","26,138","34,114","34,162","34,114","42,122","42,162","42,122","50,130","50,162","50,130","58,146","58,162","58,146","66,122","66,170","66,122","74,122","74,178","74,122","82,122","82,186","82,122","90,130","90,170","90,130","90,130","90,186","90,130","98,130","98,186","98,130","106,138","106,170","106,138","3,115","3,155","3,115","11,123","11,155","11,123","19,131","19,154","19,131","27,139","27,154","27,138","35,115","35,163","35,115","43,123","43,163","43,123","51,131","51,163","51,131","59,147","59,163","59,147","67,123","67,171","67,123","75,123","75,179","75,123","83,123","83,187","83,123","91,131","91,171","91,131","91,131","91,187","91,131","99,131","99,187","99,131","107,139","107,171","107,139","4,116","4,156","4,116","12,124","12,156","12,124","20,132","20,155","20,132","28,140","28,154","28,138","36,116","36,164","36,116","44,124","44,164","44,124","52,132","52,164","52,132","60,148","60,164","60,148","68,124","68,172","68,124","76,124","76,180","76,124","84,124","84,188","84,124","92,132","92,172","92,132","92,132","92,188","92,132","100,132","100,188","100,132","108,140","108,172","108,140","5,117","5,157","5,117","13,125","13,157","13,125","21,133","21,156","21,133","29,141","29,154","29,138","37,117","37,165","37,117","45,125","45,165","45,125","53,133","53,165","53,133","61,149","61,165","61,149","69,125","69,173","69,125","77,125","77,181","77,125","85,125","85,189","85,125","93,133","93,173","93,133","93,133","93,189","93,133","101,133","101,189","101,133","109,141","109,173","109,141","6,118","6,158","6,118","14,126","14,158","14,126","22,134","22,157","22,134","30,142","30,154","30,138","38,118","38,166","38,118","46,126","46,166","46,126","54,134","54,166","54,134","62,150","62,166","62,150","70,126","70,174","70,126","78,126","78,182","78,126","86,126","86,190","86,126","94,134","94,174","94,134","94,134","94,190","94,134","102,134","102,190","102,134","110,142","110,174","110,142","7,119","7,159","7,119","15,127","15,159","15,127","23,135","23,158","23,135","31,143","31,154","31,138","39,119","39,167","39,119","47,127","47,167","47,127","55,135","55,167","55,135","63,151","63,167","63,151","71,127","71,175","71,127","79,127","79,183","79,127","87,127","87,191","87,127","95,135","95,175","95,135","95,135","95,191","95,135","103,135","103,191","103,135","111,143","111,175","111,143","8,120","8,160","8,120","16,128","16,160","16,128","24,136","24,159","24,136","32,144","32,154","32,138","40,120","40,168","40,120","48,128","48,168","48,128","56,136","56,168","56,136","64,152","54,168","64,152","72,128","72,176","72,128","80,128","80,184","80,128","88,128","88,192","88,128","96,136","96,176","96,136","96,136","96,192","96,136","104,136","104,192","104,136","112,144","112,176","112,144"]

sendcharts:
WinGet, winList, List, ahk_class Afx:0000000140000000:0:0000000000010005:0000000000000000:0000000000000000
Loop % winList
WinMenuSelectItem, % "ahk_id " winList%a_index%, , CW, %ch2%&
WinGet, winList, List, ahk_class Afx:0000000140000000:0:0000000000010005:0000000000000000:0000000000000000
Loop % winList
WinMenuSelectItem, % "ahk_id " winList%a_index%, , CW, %ch1%&
return


Left::
{
for x,y in ForLButtonNotHold
	if (y = strt)
		{
		z := x = ForLButtonNotHold .count() ? 0 : x
		strt := ForLButtonNotHold [z+1]
		rslt := strt
		break
	   	 }
	else
		rslt := ""
		ch := StrSplit(strt,",")
ch1 := ch.1
ch2 := ch.2
gosub sendcharts
return
}
I hope my question made sense
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Simple number manipulation

08 Oct 2021, 19:18

in v1 theres an expression limit of usually about 500(although that depends on the complexity)
declare ur array, then push less stuff into it chunk-wise:

Code: Select all

MyArray := []
MyArray.Push(first, bunch, of, elements)
MyArray.Push(more, stuff)
MyArray.Push(even, more)
in v2 theres also an (admittedly, way way way much higher) expression limit, but ur script would (silently, if ure not looking out for it or ur IDE is bad) crash if u exceeded it(instead of getting an error msg...)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], inseption86, just me, metallizer and 171 guests