Posts: 36
Threads: 12
Joined: Dec 2018
07-25-2020, 09:13 PM
(This post was last modified: 07-25-2020, 09:15 PM by Remotehorst23.)
Hey QM Users and Gintarras!^^
Maybe this is simple for you. Would be cool if you can help me with a snippet. I tried with several approaches but none of them worked and i have really bad programming skills. xD
I need a few hotkeys and everyone of them should trigger another function while stopping the function that was running before
I have a function that does something (one time). But in my main Macro I want to loop the execution of that function after the command (RegisteredHotKey) is given.
And if i press another hotkey it should stop repeating the function that was running before and repeat the next function that is linked with the other hotkey
These functions should be able to call other functions (like function 4, 5 or 6 who are without hotkeys but are triggered if one of a few images is found). They should pause the 1, 2 and 3 functions when they do that. After these "non-hotkey" functions were running, they should return to the function loop that was triggered by hotkey. (I think that's normal function behaviour but I'm not sure and this is why i mention it.)
Pseudocode:
Hotkey Shift+Alt+1
Hotkey Shift+Alt+2
Hotkey Shift+Alt+3
if Shift+Alt+1
stop function 2+3
rep function 1
if Shift+Alt+2
stop function 1+3
rep function 2
if Shift+Alt+3
stop function 1+2
rep function 3
---
simultaneous:
scan for image 1, if found run function 4
scan for image 2, if found run function 5
scan for image 3, if found run function 6
Doing this only with if, else and if(scan) etc. creates such a chaotic macro that I can't even understand what I did. So it would be very cool if there is a more clean and easy to understanding code that I can add things to it. But if thats not so easy in a clean way, i am happy with anything that helps me to run the code.
Thanks for trying to save my life! ;p
Posts: 229
Threads: 22
Joined: Sep 2007
Function Function16
Trigger SA4
shutdown -6 0 "Function14"
shutdown -6 0 "Function12"
shutdown -6 0 "Function13"
Function Function15
int w=win("" "Chrome_WidgetWin_1")
rep
,if(scan("image:h1C59368C" w 0 1|2|16))
,,Function9
,if(scan("image:h1C59368C" w 0 1|2|16))
,,Function8
,if(scan("image:h1C59368C" w 0 1|2|16))
,,Function7
Function test2
Function test
Function test3
Function Function13
Trigger SA2
shutdown -6 0 "Function14"
shutdown -6 0 "Function12"
rep
,test2
Function Function14
Trigger SA3
shutdown -6 0 "Function12"
shutdown -6 0 "Function13"
rep
,test3
Function Function12
Trigger SA1
shutdown -6 0 "Function14"
shutdown -6 0 "Function13"
rep
,test
Posts: 36
Threads: 12
Joined: Dec 2018
Thank you redbull2k,
now I now know that I can use shutdown -6 to stop a function, but everything else is confusing me even more and I can't see or understand what these snippets do other than starting or stopping functions or loops.
Sorry, but this doesn't help. Like I said before I'm not good at programming. The only thing I notice is, that there is no macro running these functions. The labels you used are only confusing me even more. It looks pretty random to me and I can't imagine how this could work.
I really took some time to try to understand the code and while I think that I understood a part of the concept, I'm not sure how to implement it in my macro to make it work the way i need it. I hope somebody can explain this to me.
Your help is very much appreciated! Thanks in advance!
Posts: 229
Threads: 22
Joined: Sep 2007
Posts: 36
Threads: 12
Joined: Dec 2018
07-26-2020, 12:29 PM
(This post was last modified: 07-26-2020, 01:41 PM by Remotehorst23.)
Thanks! Now i understand a bit better.
In function 1, 2 and 3 i have some image scans and if then else going on. The thing is, that these are acutally macros but i want to clean it up because its getting more and more complicated. So i need to make them functions, called from a main macro (not only from hotkeys because i want more ways to trigger a function).
One of these macros is looking like that:
Macro [b]KleeSammler[/b] [help1][/help1]
[code];start
out "Re/Start"
ifk(F12) end ;;end if F12 is pressed
,out "User stopped"
if(scan("resource:Gruppe_beitreten_Nein.bmp" 0 0 1|16 30))
,wait 0.2
,lef
,goto start
else
,goto start2
;start2
wait 0.5
if(scan("resource:bereit.bmp" 0 0 1|16 20))
,goto kampfvorbereitung
else
,goto weiter
;weiter
if(scan("resource:ok.bmp" 0 0 1|16 20))
,wait 0.5
,out "levelup"
,lef
,goto sammeln
else
,;sammeln
,out "scanning"
,if(scan("resource:klee_2.bmp" 0 0 1|16 42))
,,OnScreenDisplay "Klee sammeln 1" 1
,,out "Klee Sammeln 1"
,,wait 0.5
,,lef
,,wait 0.5
,,if(scan("resource:pflueck.bmp" 0 0 1|16 50))
,,,wait 0.5
,,,out "pfluecken"
,,,lef
,,,wait 8
,,,goto start
,,else
,,,goto start
,else
,,out "kein klee gefunden"
,,goto start
;kampfvorbereitung
wait 0.2
if(scan("resource:Kampfmodus_Sperren.bmp" 0 0 1|16 40))
,out "Kampf gesperrt"
,wait 0.2
,lef
,goto vor2
else
,;vor2
,if(scan("resource:Kampfmodus_zuschauer.bmp" 0 0 1|16 30))
,,out "Zuschauen verboten"
,,wait 0.1
,,lef
,,goto vor3
,else
,,;vor3
,,if(scan("resource:Kampfmodus_map.bmp" 0 0 1|16 30))
,,,out "Kampfmodus Map"
,,,wait 0.1
,,,lef
,,,goto ready
,,else
,,,;ready
,,,if(scan("resource:bereit.bmp" 0 0 1|16 20))
,,,,out "Kampf Start: Bereit"
,,,,wait 0.2
,,,,lef
,,,,goto infight
;infight
out "start infight"
wait 0.5
if(scan("resource:KampfAmZug.bmp" 0 0 1|16 30))
,out "Am Zug!"
,wait 0.2
,if(scan("resource:Zielsuchzeiger.bmp" 0 0 1|16 30))
,,out "Zielsuchzeiger"
,,lef
,,wait 0.5
,,if(scan("resource:ZielsuchzeigerSetzen2.bmp" 0 0 1|16 20))
,,,wait 0.2
,,,lef
,,,wait 0.2
,,,out "Zeiger gesetzt"
,,,mou
,,,goto rundenende
,,else
,,,out "Kann Zielsuchzeiger nicht setzen"
,,,if(scan("resource:ZielsuchzeigerSetzenNacht.bmp" 0 0 1|16 30))
,,,,wait 0.2
,,,,lef
,,,,wait 0.2
,,,,out "Zeiger gesetzt"
,,,,mou
,,,,goto rundenende
,,,else
,,,,if(scan("resource:a_zeiger.bmp" 0 0 1|16 40))
,,,,,out "Normaler Zeigerangriff"
,,,,,wait 0.2
,,,,,lef
,,,,,wait 0.2
,,,,,if(scan("resource:ALLEgegnerAngreifenImKampf.bmp" 0 0 1|16 5))
,,,,,,out "Gegner gefunden"
,,,,,,wait 0.2
,,,,,,lef
,,,,,,wait 0.5
,,,,,,goto rundenende
,,,,else
,,,,,out "Kein Gegner auswählbar"
,,,,,;rundenende
,,,,,wait 2.5
,,,,,if(scan("resource:rundenende.bmp" 0 0 1|16 50))
,,,,,,out "Runde beenden"
,,,,,,lef
,,,,,,wait 1
,,,,,,if(scan("resource:kampfende.bmp" 0 0 1|16 40))
,,,,,,,wait 0.2
,,,,,,,lef
,,,,,,,out "kampf beendet - Zutatensuche fortsetzen"
,,,,,,,goto start
,,,,,,else
,,,,,,,goto infight
,,,,,else
,,,,,,out "Kann Runde nicht beenden - Zweiter versuch"
,,,,,,wait 0.5
,,,,,,if(scan("resource:rundenende.bmp" 0 0 1|16 60))
,,,,,,,out "Runde beenden"
,,,,,,,lef
,,,,,,,goto infight
,,,,,,else
,,,,,,,out "Kampf anscheinend beendet"
,,,,,,,goto kampfende
else
,wait 2
,if(scan("resource:kampfende.bmp" 0 0 1|16 60))
,,wait 0.2
,,lef
,,out "kampf beendet - Zutatensuche fortsetzen"
,,goto start
,else
,,if(scan("resource:kampfende.bmp" 0 0 1|16 70))
,,,wait 0.2
,,,lef
,,,out "kampf beendet - Zutatensuche fortsetzen"
,,,goto start
,,goto infight
;kampfende
wait 1
if(scan("resource:kampfende.bmp" 0 0 1|16 60))
,wait 0.2
,lef
,out "kampf beendet - Zutatensuche fortsetzen"
,goto start
else
,out "Kampf anscheinend nicht beendet - Kampf fortsetzen"
,goto infight
[/code]
This macro searches for plants to collect and if the player gets into a fight (turn based), it switches to the "kampfvorbereitung" (fightpreparation) mode. Because there are many different plants, i would need to copy the code to the other macros wich makes no sense if i can also use functions. I guess that would be more clean and better to work with.
I need to make this Macro a function, calling other functions (for battle mode). And then i have like 5 other macros like that, doing (almost) the same thing who collect other plants and also need to be able to detect if the player gets into a battle. I need to clean them up too.
The idea with the hotkey triggers is good to know, but i want to have it in the main macro (my first post pseudo code) because when i have everything working, i want to be able to also remote control my game from a telegram chat when im not at home. (Does this mean i should trigger functions by hotkeys and by reading telegram chat who both change the same variables?)
I think i can read the Telegramchat with a telegram bot, but it would be cool if QM can handle that too. I already tried, but had no good results until now. Please see this thread for Telegram script (scanning for images too xD) https://www.quickmacros.com/forum/showth...p?tid=6963
Actually all my code is a mess like the one i posted right now and every macro has a few little bugs or missing code. But the main question that arises is, how should i create the structure of the main macro to have everything clean and working? Overall i think i need to scan for at least 3-5 different images at the same time and i want to prevent scanning for images too much. Would be great if there is a better solution for my telegram macro. Ingame there is no other way than scanning for images wich is ok.
Thanks very much for your help!
Posts: 229
Threads: 22
Joined: Sep 2007
First of all you need to paste code correctly
highlight all text in function and right click> other formats >copy qm forum and paste here.
Posts: 36
Threads: 12
Joined: Dec 2018
Thanks for the hint! Previous Post updated.
Posts: 229
Threads: 22
Joined: Sep 2007
you can also use
Function Function4
,,if(scan("resource:ZielsuchzeigerSetzen2.bmp" 0 0 1|16 20) or scan("resource:ZielsuchzeigerSetzenNacht.bmp" 0 0 1|16 30))
,,,wait 0.2
,,,lef
,,,wait 0.2
,,,out "Zeiger gesetzt"
,,,mou
,,,goto rundenende
This can help reduce code lines.
if(scan("resource:ZielsuchzeigerSetzen2.bmp" 0 0 1|16 20) and scan("resource:ZielsuchzeigerSetzenNacht.bmp" 0 0 1|16 30)) ;;must find both images
Posts: 36
Threads: 12
Joined: Dec 2018
That's good to know too! Thanks!
What about the main structure of the macro that triggers all the functions?
What would be the best practice for that if I want several different triggers like hotkeys or telegram messages?
And do you know if it would be easier or better to use discord for that instead of telegram?
|