Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send changed variables to already running function without pausing macro? Solved
#1
Hey,

I hope someone can help me or give me some hints. I would be very grateful!

I got a Macro that calls several functions. To have my code clean and with a good overview (i need that because im a noob and i want to expand the macro with more functions), I use sel case with registered Hotkeys. I hope this also helps me to not waste too many resources.

The Hotkeys are used as toggles to change variables. These variables should then be passed to a function that updates and runs without pausing the main macro (that's my main problem).
The function can or should be restarted if a parameter(variable) changes but I don't know how to do it.

This is the Macro I created. I make it to help me save some clicks and actions but I want to be able to change the macro settings so I can choose what kind of clicks it should do (or not).
 
Code:
Copy      Help
Macro [b]PlayerHelper[/b] [help1][/help1]
[code]__RegisterHotKey hk1.Register(0 1 MOD_CONTROL|MOD_SHIFT 'X')
__RegisterHotKey hk2.Register(0 2 MOD_CONTROL|MOD_SHIFT 'Y')
__RegisterHotKey hk3.Register(0 3 MOD_CONTROL|MOD_SHIFT 'C')
__RegisterHotKey hk4.Register(0 4 MOD_CONTROL|MOD_SHIFT VK_F12)

int x ;;Kampfsperre
x=0

int y ;;Zuschauverbot
y=0

int c ;;Taktikmodus
c=0

MSG z
rep
,if(GetMessage(&z 0 0 0)<1) break
,sel z.message
,,case WM_HOTKEY
,,sel z.wParam
,,,case 1
,,,x+1
,,,if(x=1)
,,,,out "X = %i" x
,,,,OnScreenDisplay "Kampfsperre" -1 20 100 "Arial" 20 0x00FFFF 8 "1"
,,,,mac "CombatSettings" "%i" "%i" "%i" x y c
,,,else
,,,,x=0
,,,,out "X = %i" x
,,,,OsdHide "1"
,,,,;; end function
,,,,
,,,case 2
,,,y+1
,,,if(y=1)
,,,,out "Y = %i" y
,,,,OnScreenDisplay "Zuschauverbot" -1 20 140 "Arial" 20 0x00FFFF 8 "2"
,,,,mac "CombatSettings" "%i" "%i" "%i" x y c
,,,else
,,,,y=0
,,,,out "Y = %i" y
,,,,OsdHide "2"
,,,,;; end function
,,,,
,,,case 3
,,,c+1
,,,if(c=1)
,,,,out "C = %i" c
,,,,OnScreenDisplay "Taktikmodus" -1 20 180 "Arial" 20 0x00FFFF 8 "3"
,,,,mac "CombatSettings" "%i" "%i" "%i" x y c
,,,else
,,,,c=0
,,,,out "C = %i" c
,,,,OsdHide "3"
,,,,;; end function
,,,,
,,,case 4
,,,OnScreenDisplay "END" 3 50 400 "Arial" 20 0x00FFFF
,,,ret
,DispatchMessage &z
[/code]

The Function needs to stay active and repeat but only scan for the images that are activated by the variables. That means, if the main macro changes variables, they need to be passed to the function without the function pausing the main macro (but thats what's happening now). I hope this explained my problem well enough.
 
Code:
Copy      Help
Function [b]CombatSettings[/b] [help1][/help1]
[code]function# x y c ;;x=kampfsperre y=zuschauverbot c=taktikmodus

rep
,if(x=1)
,,if(scan("resource:Kampfmodus_Sperren.bmp" 0 0 1|16 30))
,,,wait 0.5
,,,lef
,
,if(y=1)
,,if(scan("resource:Kampfmodus_zuschauer.bmp" 0 0 1|16 30))
,,,wait 0.5
,,,lef
,
,if(c=1)
,,if(scan("resource:Kampfmodus_map.bmp" 0 0 1|16 30))
,,,wait 0.5
,,,lef
,
[/code]

Actually it looks like it only calls the function once and pauses the macro when i use one of the hotkeys (when the function starts). But the macro should continue to run and "update" the function - give it the new variables. It wouldn't be a problem if the function stops and restarts if that would be the only way to do it. I just don't know how to do it. xD

The function should also repeat, maybe until I give it a fourth variable to stop it (that would be awesome but its also beyond my skills!). I consider myself as QM noob so please (if the solution is complicated) give me an explanation of what happens. Thank you!

I already managed to have asynchronous copies of the function running, but when I play and always change the few hotkey toggles, there are more and more functions that cause lag after some time.

I also found out that I  can get the id of a function withgetopt itemid

QM Help says this would be faster than qmitem command.int i=qmitem("MyFunctionName" 1)


But i can't find examples of how to use getopt itemid.

I already got qmitem working (partially). But when I run the macro and try to get access to the function it always gives me an "Exception Error 0xC0000005. Access violation"
No matter how I tried, it didn't work for me. Please help! Sad

Thanks in advance for any tips or help!


Messages In This Thread
Send changed variables to already running function without pausing macro? Solved - by Remotehorst23 - 08-04-2020, 11:09 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)