problems with simple If else loop(im noob)..

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
qwerty84
Newbie
Posts: 2
Joined: Tue Feb 20, 2007 5:25 am

problems with simple If else loop(im noob)..

Post by qwerty84 » Tue Feb 20, 2007 5:47 am

i wanted to do a simple macro.. if i press 1, ctrl 1 will be entered, if i press 2 ctrl 2 wil be entered.. Below are the codes i have.. The loops isnt working. What am i doing wrong? :idea:

Label>start
If> Send> = 1
{
Press CTRL
Send Character/Text>1
Release CTRL
Label>end
}
ELSE If> Send> = 2
{
Press CTRL
Send Character/Text>2
Release CTRL
Label>end
}
ELSE
{
Goto>start
}
Endif

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 20, 2007 8:33 am

Hi,

The syntax you are using is not Macro Scheduler syntax. And you can't embed functions inside others. The Send command *SENDS* characters. It simulates the user pressing those keys. It does not detect when YOU press those keys. For that use OnEvent. You want something like:

Code: Select all

OnEvent>KEY_DOWN,1,0,DoCTRL1
OnEvent>KEY_DOWN,2,0,DoCTRL2
OnEvent>KEY_DOWN,3,0,DoCTRL3

Label>main
  Wait>0.2
Goto>main

SRT>DoCTRL1
  Press CTRL
  Send>1
  Release CTRL
END>DoCTRL1

SRT>DoCTRL2
  Press CTRL
  Send>2
  Release CTRL
END>DoCTRL2

SRT>DoCTRL3
  Press CTRL
  Send>3
  Release CTRL
END>DoCTRL3
For testing purposes try adding a MessageModal into the subroutines to see the event being fired ...
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

qwerty84
Newbie
Posts: 2
Joined: Tue Feb 20, 2007 5:25 am

Post by qwerty84 » Thu Feb 22, 2007 3:16 pm

its working. thanks :D

rawill
Newbie
Posts: 15
Joined: Fri Feb 23, 2007 7:06 am
Location: Australia

Post by rawill » Fri Feb 23, 2007 7:26 am

I have much the same problem, any help to get mine working will be much appreciated.

Basically what I am trying to achieve here is to have a variable that changes based upon where it is up to.

So if the BM is 0 it starts from the top, adds +1 to itself to make 0+1, then the next time round it looks to see what BM is again.
My problem is the if and else if, i dont know how to write it to make it register the else before moving on.

Currently if i force BM to be 2 instead of zero it doesn't check to see what BM is in the first set, it doesn't appear to set the envar to be the number I asked, but rather it skips them and just goes straight for the Goto>BM1

HERE is my actual MJT Script

SetEnvVar>BM,0

Label>Start

if>BM,=0
SetEnvVar>BM,1
Goto>BM1

Else>
if>BM,=1
SetEnvVar>BM,2
Goto>BM2

Else>
if>BM,=2
SetEnvVar>BM,3
Goto>BM3

Else>
if>BM,=3
SetEnvVar>BM,4
Goto>BM4

Else>
if>BM,=4
SetEnvVar>BM,5
Goto>BM5

Else>
if>BM,=5
SetEnvVar>BM,0
Goto>BM6

Endif
Endif
Endif
Endif
Endif
Endif


Label>BM1
Message>This is Bookmark One(1)
Goto>Start

Label>BM2
Message>This is Bookmark Two(2).
Goto>Start

Label>BM3
Message>This is Bookmark Three(3).
Goto>Start

Label>BM4
Message>This is Bookmark Four(4).
Goto>Start

Label>BM5
Message>This is Bookmark Five(5).
Goto>Start

Label>BM6
Message>This is Bookmark Six(6).
Goto>Start

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Feb 23, 2007 10:36 am

I'm not sure why you want to use SetEnvVar. And you also don't need those gotos. You have commas in your If statements. I think you want something more like this:

Code: Select all

Let>BM=0
Label>start

if>BM=0
  Let>BM=1
  MessageModal>This is Bookmark One(1)
Else
  if>BM=1
    Let>BM=2
    MessageModal>This is Bookmark Two(2)
  Else
    if>BM=2
      Let>BM=3
      MessageModal>This is Bookmark Three(3)
    Else
      if>BM=3
        Let>BM=4
        MessageModal>This is Bookmark Four(4)
      Else
        if>BM=4
          Let>BM=5
          MessageModal>This is Bookmark Five(5)
        Else
          if>BM=5
            Let>BM=6
            MessageModal>This is Bookmark Six(6)
          Endif
        Endif
      Endif
    Endif
  Endif
Endif

If>BM<6>start
Endif
I have no idea if this is really what you want to do, but this script meets your stated requirements.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Feb 23, 2007 10:39 am

These simpler scripts achieve the exact same thing:

This one goes up to 6:

Code: Select all

Let>BM=0
Repeat>BM
  Let>BM=BM+1
  MessageModal>This is Bookmark %BM%
Until>BM=6
This one increments ad infinitum:

Code: Select all

Let>BM=0
Label>start
  Let>BM=BM+1
  MessageModal>This is Bookmark %BM%
Goto>start
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

rawill
Newbie
Posts: 15
Joined: Fri Feb 23, 2007 7:06 am
Location: Australia

Post by rawill » Sat Feb 24, 2007 1:55 am

Thankyou so much, I guess most of it just comes down to logic and knowing how to tap this stuff out in the mjtnet language.

But this atleast will help with a few others im struggling with too :)

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts