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

Simple number manipulation

16 Sep 2021, 06:12

Hi all, essentially all I need is manipulation of two numbers

- Start is 1,14

and a dictionary of

- If aa,bb is active, and right is pressed change to cc,gg (cc,gg are any integers I choose)’

- if left was pressed instead of write, would have changed to different integers, i.e. to bb,dd

that is all

just need a function to allow me to manually modify the desired sequences, as opposed to me writing out each individual if statement
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Simple number manipulation

16 Sep 2021, 06:54

Code: Select all

num   :=  [ 1, 14]
Left  := [[ 3, 23], [ 9, 90]]
Right := [[19, 60], [12, 22]]
Gosub, Show
Left::
Right::
%A_ThisHotkey%.Push(num := %A_ThisHotkey%.RemoveAt(1))
Show:
MsgBox, 64, Numbers, % num.1 " and " num.2
Return
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

16 Sep 2021, 07:53

Thanks v much, just two points then it's all complete

Point 1:

Code: Select all

num   :=  [ 1, 14]
Left  := [[ 3, 23], [ 9, 90]]
Right := [[19, 60], [12, 22],[b][3,23][/b]]
If we are at 3,23, in bold, and press left, we should get 9,90. At the moment, we get 3,23, as if each button has it's own sequence in memory, which is wrong. We only ever need the active numbers in memory, and everything preceeding that is irrelevant.

Point 2:

This seems to not work under an #IfWinactive condition?
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Simple number manipulation

16 Sep 2021, 08:09

If you have a revised script using a directive, then post the revised script.

You have provided only partial descriptions of your need. Provide a complete description, and a complete example of it, from start to finish.

Another example:

Code: Select all

set :=  [[1, 14], [3, 23], [9, 90], [19, 60], [12, 22]], n := 1
#IfWinActive ahk_exe notepad.exe
Left::
Right::
n := A_ThisHotkey = "Left" ? --n ? n : set.Count() : n++ - set.Count() ? n : 1
Send % set[n].1 ", " set[n].2 "`n"
Return
#IfWinActive
Last edited by mikeyww on 16 Sep 2021, 08:20, edited 1 time in total.
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

16 Sep 2021, 08:20

Thanks for the reply.

Code: Select all

num   :=  [ 1, 14]
Left  := [[ 3, 23], [ 9, 90]]
Right := [[19, 60], [12, 22]]
So the above will look more like

Code: Select all

num   :=  [ 1, 14]
Left  := [[ 3, 23], [ 9, 90]...]
Right := [[19, 60], [12, 22]...]
Up  := [[ 8, 45], [ 9, 165]...]
Down := [[6, 51], [..., ...]...]
Enter:= [...]
...
I just need the functionality, then I can manually add and modify the desired numbers I need.

Any time a button is pressed, IF it's within the chain for the pressed button, it would send the two numbers directly after it in it's own sequence.

Example - [3,23] could be in every single sequence (for left/right/up/down/enter/more buttons), but it being active at the same time the specific button is pressed is crucial to what the next number will be.
Last edited by blad4 on 16 Sep 2021, 08:41, edited 1 time in total.
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Simple number manipulation

16 Sep 2021, 08:23

Your script has multiple bugs. Simplify it until it works with something very simple. See documentation about auto-execute section and #If directives, which apply only to hotkeys & hotstrings. Unlabeled code following Return is unreachable and will not execute.

Your post provides no specific examples from start to finish. I will give up until that time.
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

16 Sep 2021, 08:39

Hope this makes sense.. the logic is that we are just mapping custom sequences which interact with eachother, so you can see the routes to writing them out is impossible, as the aim is to be able to add and adjust buttons and combos

Code: Select all

num   :=  [ 1, 14]
Left  := [[ 3, 23], [ 9, 90], [3,23], [58,105]]
Right := [[19, 60], [12, 22], [3,23], [4,65]]

Assume start 1,14
L: 3,23
L: 9,90
L: 3,23
L: 58,105
L: 3,23
etc...

Another version

L: 3,23
L: 9,90
L: 3,23
R: 4,65
R: 19,60
R: 12,22
R: 3,23
R: 4,65
etc...

Another

L: 3,23
L: 9,90
L: 3,23
R: 4,65
R: 19,60
R: 12,22
R: 3,23
R: 4,65
L: NOTHING
R: 19,60

Another

R: 19,60
R: 12,22
R: 3,23
L: 58,105
...
Last edited by blad4 on 16 Sep 2021, 12:22, edited 1 time in total.
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Simple number manipulation

16 Sep 2021, 09:30

I am following most of the sequences.

QUESTION #1. What is the rule that should get from line 34 to line 35?

QUESTION #2. If line 34 were "L", what numbers would be used at that point?
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

16 Sep 2021, 09:41

QUESTION #1.

There are no rules per se, when referring to 'R' or 'L'. These are merely the buttons I choose to press

For line 34, num was [4,65], then I happened to press Left, yielding [3,23]

QUESTION #2

If Line 34 was from the L chain, it would have meant we pressed Left on Line 33, yielding:

Line 34:

Code: Select all

L: 9,90
User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Simple number manipulation

16 Sep 2021, 09:54

Seems like the transition from line 35 to 36 is what doesn’t make sense. Line 35 should have been the first instance of [3, 23], so jumping to [4, 65] from there does not follow the previous logic. Line 36 should be [12, 22].
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Simple number manipulation

16 Sep 2021, 10:10

Right (or Left)! I am hearing that there are no rules here. Since I am not seeing how to write a script that follows this exact pattern that has been outlined in the example, I will let others accomplish it!
User avatar
flyingDman
Posts: 2776
Joined: 29 Sep 2013, 19:01

Re: Simple number manipulation

16 Sep 2021, 10:14

Is this the idea?:

Code: Select all

Left  := [[ 3, 23], [ 9, 90], [3,23], [58,105]]
Right := [[19, 60], [12, 22], [3,23], [4,65]]
cnt := 0

left::
cnt := cnt = 4 ? 1 : ++cnt
tooltip, % left[cnt][1] " " left[cnt][2]
return

right::
cnt := cnt = 4 ? 1 : ++cnt
tooltip, % right[cnt][1] " " right[cnt][2]
return
14.3 & 1.3.7
User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Simple number manipulation

16 Sep 2021, 10:18

Yes, I think there are definite rules that flyingDman captured. It’s just that there was a mistake in the examples that violated the rules.
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

16 Sep 2021, 10:19

I just checked adding more to the sequence on flyingDman's and they did not get recognised

But that is the exact idea, yes. Now we just need to make it responsive to user edits nad modifications.

Also, logically, if left is pressed at 12,22 for instance, it should not call any new numbers. The only time it should, in the Right chain, is at 3,23, because there is (2x) [3,23] present in the Left chain. Thus the logic is obviously we get 9,90 (not 58,105 even though that comes after the second [3,23].
User avatar
flyingDman
Posts: 2776
Joined: 29 Sep 2013, 19:01

Re: Simple number manipulation

16 Sep 2021, 10:24

The lines:

Code: Select all

cnt := cnt = 4 ? 1 : ++cnt
should be replaced with

Code: Select all

cnt := cnt = left.count() ? 1 : ++cnt
and

Code: Select all

cnt := cnt = right.count() ? 1 : ++cnt
14.3 & 1.3.7
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

16 Sep 2021, 12:13

Thank you, this is quite functional, but still relies on us moving ahead in the sequence globally by one.

Take for example, when just pressing right 3 times, then left 1 time.

Code: Select all

Left  := [[ 3, 23], [ 9, 90], [3,23], [58,105], [89,11]]
Right := [[19, 60], [12, 22], [3,23], [4,65], [89,11]]
We land at 3,23 before pressing left. Desired result it 9,90, but instead is yielding 58,105.

Code: Select all

Left  := [[ 3, 23], [ 9, 90], [3,23], [58,105], [89,11]]
Right := [[19, 60], [12, 22], [3,23], [4,65], [89,11]]
Assume we press left 1 time, getting 3,23 then right 1 time. At the moment it gets 12,22, what we should get is 4,65 (the set immediately after 3,23)
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation

16 Sep 2021, 12:19

boiler wrote:
16 Sep 2021, 09:54
Seems like the transition from line 35 to 36 is what doesn’t make sense. Line 35 should have been the first instance of [3, 23], so jumping to [4, 65] from there does not follow the previous logic. Line 36 should be [12, 22].
This is 100% correct regarding the error, but it should read like a 'null' response, because pressing left at 4,65 should not have a consequence. Just changed it now
User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Simple number manipulation so, how did it get there

16 Sep 2021, 14:40

blad4 wrote:
16 Sep 2021, 12:13
Thank you, this is quite functional, but still relies on us moving ahead in the sequence globally by one.

Take for example, when just pressing right 3 times, then left 1 time.

Code: Select all

Left  := [[ 3, 23], [ 9, 90], [3,23], [58,105], [89,11]]
Right := [[19, 60], [12, 22], [3,23], [4,65], [89,11]]
We land at 3,23 before pressing left. Desired result it 9,90, but instead is yielding 58,105.

Code: Select all

Left  := [[ 3, 23], [ 9, 90], [3,23], [58,105], [89,11]]
Right := [[19, 60], [12, 22], [3,23], [4,65], [89,11]]
Assume we press left 1 time, getting 3,23 then right 1 time. At the moment it gets 12,22, what we should get is 4,65 (the set immediately after 3,23)
What you’re saying it actually does is exactly what I expected it to do. I don’t see the logic in what you are now describing. You said before there are no rules. That cannot be the case since you have an expected outcome. You are going to need to try to articulate the rules to land on what you are describing.

The second example above especially does not make sense to me. After pressing left one time, it should be at 3, 23 because it’s at the first instance of 3, 23 in the top sequence. To get 4, 65 after pressing right would suggest that it somehow was at the second instance of 3, 23 in the top sequence of numbers before right was pressed. If so, how was it supposed to have gotten there?
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Simple number manipulation so, how did it get there

16 Sep 2021, 16:22

boiler wrote:
16 Sep 2021, 14:40
blad4 wrote:
16 Sep 2021, 12:13
Thank you, this is quite functional, but still relies on us moving ahead in the sequence globally by one.

Take for example, when just pressing right 3 times, then left 1 time.

Code: Select all

Left  := [[ 3, 23], [ 9, 90], [3,23], [58,105], [89,11]]
Right := [[19, 60], [12, 22], [3,23], [4,65], [89,11]]
We land at 3,23 before pressing left. Desired result it 9,90, but instead is yielding 58,105.

Code: Select all

Left  := [[ 3, 23], [ 9, 90], [3,23], [58,105], [89,11]]
Right := [[19, 60], [12, 22], [3,23], [4,65], [89,11]]
Assume we press left 1 time, getting 3,23 then right 1 time. At the moment it gets 12,22, what we should get is 4,65 (the set immediately after 3,23)
What you’re saying it actually does is exactly what I expected it to do. I don’t see the logic in what you are now describing. You said before there are no rules. That cannot be the case since you have an expected outcome. You are going to need to try to articulate the rules to land on what you are describing.

The second example above especially does not make sense to me. After pressing left one time, it should be at 3, 23 because it’s at the first instance of 3, 23 in the top sequence. To get 4, 65 after pressing right would suggest that it somehow was at the second instance of 3, 23 in the top sequence of numbers before right was pressed. If so, how was it supposed to have gotten there?
Thanks Boiler. There should actually be independence of the sequences. Let me make some drawings and add to this post to further elaborate, and I'm going to completely rejig the sense of forward direction within the sequences for now, for utmost simplicity, as I can now see where my rules are not making sense.

Essentially, without any duplicate sets within one sequence, we do not need to count where we are in the cycle. Only thing in memory we need is the imminent set to be changed.
Attachments
ahk1.png
ahk1.png (20.98 KiB) Viewed 1244 times
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Simple number manipulation

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], morkovka18 and 174 guests