How do I write this

Post gaming related scripts
Nwb
Posts: 110
Joined: 29 Nov 2016, 08:56

How do I write this

27 Dec 2017, 23:46

Can somebody help me write this script? I'm really confused and keep messing it up.

Here is what I want to happen.

Code: [Select all] [Download] GeSHi © Codebox Plus

F7::
Toggleplant:
toggle3 := !toggle3


Starts the block of script ^

Code: [Select all] [Download] GeSHi © Codebox Plus

if toggle3
Menu, tray, Rename, Start Planting (F7), Stop Planting (F7)

else
Menu, tray, Rename, Stop Planting (F7), Start Planting (F7)


This is for menu ^

Now, after that, I want a loop to happen. A loop that lasts one hour. This is the mother loop.

There is a subloop inside the mother loop which lasts for 50seconds.
Here is what happens in the subloop:

Code: [Select all] [Download] GeSHi © Codebox Plus

    ControlSend, ahk_parent, {Blind}{right down}, ahk_exe Growtopia.exe
Sleep, %collectspeed%
ControlSend, ahk_parent, {Blind}{right up}, ahk_exe Growtopia.exe


Sleep, 50

ControlSend, ahk_parent, {Blind}{right down}, ahk_exe Growtopia.exe
Sleep, %collectspeed%
ControlSend, ahk_parent, {Blind}{right up}, ahk_exe Growtopia.exe


^ This keeps looping for 50seconds.
After the loop is over,
an action is performed. That action is:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



^ After this action is done, the entire set of actions inside the mother loop is done. The actions inside the mother loop keep looping for 1hour.

Can somebody help me make this? :)
Last edited by Nwb on 28 Dec 2017, 00:56, edited 1 time in total.
Your regular ahk newbie. Feel free to correct me! don't stop me from trying.
User avatar
Exaskryz
Posts: 2812
Joined: 17 Oct 2015, 20:28

Re: How do I write this

28 Dec 2017, 00:44

You may want make that F7 a hotkey (double colon)? But if you only want it controlled by the menu, I'd recommend not using a key name just to avoid that confusion. It's fine do use just an F7: label if you really want to.

You'll need to make the Menu, Tray, Add, ___, etc.

I would recommend using SetTimer instead of a Loop to do your commands. You can use If with A_ThisMenuItem to know if you clicked the Start or Stop planting. You can then turn on or off timers.
Nwb
Posts: 110
Joined: 29 Nov 2016, 08:56

Re: How do I write this

28 Dec 2017, 00:50

Exaskryz wrote:You may want make that F7 a hotkey (double colon)? But if you only want it controlled by the menu, I'd recommend not using a key name just to avoid that confusion. It's fine do use just an F7: label if you really want to.

You'll need to make the Menu, Tray, Add, ___, etc.

I would recommend using SetTimer instead of a Loop to do your commands. You can use If with A_ThisMenuItem to know if you clicked the Start or Stop planting. You can then turn on or off timers.


Yea I've got the rest of the script done, and F7 is an alternative hotkey for when I don't want to reach for the menu.
(Oh yea I didn't notice that I put just one double colon, thanks)
I tried settimer but I keep messing up that's why I need help, I have no clue what or how to do that.
Your regular ahk newbie. Feel free to correct me! don't stop me from trying.
User avatar
Exaskryz
Posts: 2812
Joined: 17 Oct 2015, 20:28

Re: How do I write this  Topic is solved

28 Dec 2017, 00:59

Let's see exactly what you final code is when it's put together.

Here's an example of doing this for about 50 seconds. I'll add in a new concept of using a counter.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



If you wanted to stop it midway, make sure you call both SetTimer, mylabel, Off and counter_A:=0 or make sure counter_A:=0 is always done when you turn On the timer. If you don't, you could interrupt the script when counter_A is equal to 72, and only 28 iterations later it would turn the timer off.

When you do reach the If counter_A=100, you can then have it jump to the part of the script you want running after it, which appears to be this code, with GoSub:

Code: [Select all] [Download] GeSHi © Codebox Plus

; previous code
If counter_A=100 ; 50 ms * 100 = 50 seconds
{
SetTimer, mylabel, Off
counter_A:=0
GoSub, next_actions
}
return


Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Then maybe at the end of your next_actions you can turn the timer back on.

(Now that I think about it, the timer does not have to be turned off before the GoSub, as the GoSub should keep the thread active. But you may like it for clarity. It shouldn't hurt to have it.)
Nwb
Posts: 110
Joined: 29 Nov 2016, 08:56

Re: How do I write this

28 Dec 2017, 01:05

That's perfect now I want the entire thing to loop for an hour. And F7 to also stop the block of script.
When it stops the timer should reset to 0 along with A.
Your regular ahk newbie. Feel free to correct me! don't stop me from trying.
User avatar
Exaskryz
Posts: 2812
Joined: 17 Oct 2015, 20:28

Re: How do I write this

28 Dec 2017, 03:58

F7 you have set up initially as being able to change toggle3. You can use If !toggle3 to turn off the timer(s); ! being the logical-not operator.

If you want to interrupt a script midway through it doing one of the blocks of actions, like where you have

Code: [Select all] [Download] GeSHi © Codebox Plus


ControlSend, ahk_parent, {Blind}{left down}, ahk_exe Growtopia.exe
Sleep, 2000
ControlSend, ahk_parent, {Blind}{left up}, ahk_exe Growtopia.exe


You'd need to code in the If check after the Sleep, 2000. And for each sleep, unless you don't mind it running to completion.

The way that I would manage running the code for an hour, because you won't have always perfectly exact sleeps, is capturing the variable A_TickCount when you start the process. (When If toggle3 is true). Then each time the timer subroutine runs, it should check to make sure (start_tickcount + 3600000 > A_TickCount). I think that number is right; TickCount is in milliseconds. There are 60 seconds to a minute, 60 minutes to an hour, so that's 3600 seconds to an hour. Times 1000 is 3600000 (five zeroes).

Go ahead and give it a stab to assembling all this code. Then we can see what is missing or if things need to be moved around to have good logic. It is late for me, so I apologize if anything I said doesn't make good sense. Thoughts trailing off or just not moving from my brain to my fingers.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 6 guests