Search code examples
randomsleep

HiroMacro - how to setup random times (sleep)


I'm using this app with this language.

In the link above, i'm refering to point 4.2.8 & 4.2.13. I want to merge these 2 bits of code together.

How do I randomise sleep?

For example:

I want to click button 1 and then button 2.
The time between button1 & button2 needs to be randomly chosen from between 1 and 10 seconds.

This is all I could find:

rand sleep 1000 10000

or

Sleep math.random(1000,10000)

Would this work?

So far I have

:start 
touchdown 0 12 123
touchMove 0 12 123 //this part is clicking Button 1 

var #sleepTime 0
rand #sleepTime 1000 10000
sleep #sleepTime
// The code you provided to randomly wait between 1 and 10 
     seconds 

touchdown 0 12 145
touchMove 0 12 145
//this part is clicking Button 2 
:end 

Solution

  • You need to write:

    var #sleepTime 0  
    rand #sleepTime 1000 10000  
    sleep #sleepTime  
    

    Using your code, and the examples in the documentation (which declares variables before ':start is used)

    var #sleepTime 0  
    :start 
    rand #sleepTime 1000 10000  
    touchPress 0 100 200
    sleep #sleepTime  
    touchPress 1 200 200
    :end
    

    I think you might need to use touchPress to simulate a button being pressed.