How to randomly choose between two potential options?

Asked by chornd

The only real language I'm familiar with is C# so I don't know anything about java or python or what "jython" even is. Effectively if the thing I want to do isn't in the docs with an example showing me how to do it I don't know how to figure it out and can't find it on google because apparently there isn't a huge backlog of questions about jython on stackexchange.

1. I'm setting up a macro for a game but I want to make sure the macro has some randomness in it to spoof any potential macro detection in the game (ie I want it to not be perfectly consistent). For example I'd like to give it two images to click on and have it randomly choose one image. So kinda how this would look in my head is: "rand(1,2) if(rand.number==1 click(a) else click(b))" but that doesn't work and I don't know what to type instead.

2. Second example of a randomness I want to do: Wait a variable amount of seconds (chosen randomly). In my mind the simplest way to express it would be: "wait(1,5)" to wait a random time between 1 and 5. Doesn't work of course, is there an easy way to do this without creating an entire rand?

3. Also couldn't find in the docs, is I want to know how to make the script move to a "backup" if it can't find something instead of just erroring and stopping because it can't find it. So how it would look in my head is: "click(d) else click(e)" but that doesn't actually work.

Can I get some guidance on setting these up? I know exactly what I need to do and how the logic/syntax should look but I don't know what the actual functions are called...

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

1. read at least once through the docs, so you have an overview about the features.

2. You need to learn a bit Python (should be rather easy for someone who knows C#)

... or try with
https://github.com/christianrondeau/SikuliSharp

Can you help with this problem?

Provide an answer of your own, or ask chornd for more information if necessary.

To post a message you must log in.