Author Topic: Having a sub repeat x times  (Read 3450 times)

0 Members and 1 Guest are viewing this topic.

Offline CoraginTopic starter

  • Wacko in Pajama's
  • Elite
  • *
  • *
  • Posts: 1641
  • Activity:
    0%
  • Reputation Power: 23
  • Coragin might someday be someone...Coragin might someday be someone...Coragin might someday be someone...Coragin might someday be someone...
  • Gender: Male
  • It Is What It Is.
  • Respect: +117
  • Referrals: 1
    • View Profile
Having a sub repeat x times
« on: January 25, 2010, 01:57:18 AM »
0
Okay, this is something I want to learn as there are a lot of things in imbuing and other areas where you want to click the same button twice or more to get to your desired result.  I knew how to do this with MQ2, but I will be damned I forgot, but I will give it a stab in the dark and see what you all have to say.

Code: [Select]
if %setimbue 15
  {
  set %clicktimes 2
  gosub DoTheClick
  }

Sub DoTheClick
repeat
for %i 0
click %x %y
set %i +1
until %i = %clicktimes
Return
Coragin

My Facebook
And now I'm better at doing what ever it is Wolverine does!

Offline Paulonius

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +304
  • Referrals: 1
    • View Profile
Re: Having a sub repeat x times
« Reply #1 on: January 25, 2010, 03:58:33 AM »
0
I have been using a REPEAT UNTIL loop with a counter.
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline CoraginTopic starter

  • Wacko in Pajama's
  • Elite
  • *
  • *
  • Posts: 1641
  • Activity:
    0%
  • Reputation Power: 23
  • Coragin might someday be someone...Coragin might someday be someone...Coragin might someday be someone...Coragin might someday be someone...
  • Gender: Male
  • It Is What It Is.
  • Respect: +117
  • Referrals: 1
    • View Profile
Re: Having a sub repeat x times
« Reply #2 on: January 25, 2010, 04:01:22 AM »
0
I guess what i did about the same thing, just more complicated huh?
Coragin

My Facebook
And now I'm better at doing what ever it is Wolverine does!

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +600
  • Referrals: 2
    • View Profile
Re: Having a sub repeat x times
« Reply #3 on: January 25, 2010, 05:22:12 AM »
0
Okay, this is something I want to learn as there are a lot of things in imbuing and other areas where you want to click the same button twice or more to get to your desired result.  I knew how to do this with MQ2, but I will be damned I forgot, but I will give it a stab in the dark and see what you all have to say.

Code: [Select]
if %setimbue 15
  {
  set %clicktimes 2
  gosub DoTheClick
  }

Sub DoTheClick
repeat
for %i 0
click %x %y
set %i +1
until %i = %clicktimes
Return

Well you're syntax is a little off there with your for loop. This isn't the way I would code that particular logic but, if I did, I would do it like this:
Code: [Select]
if %setimbue 15
  {
  set %clicktimes 2
  gosub DoTheClick
  }

Sub DoTheClick
    for %i 1 %clicks
       click %x %y
Return

Personally I would do something like:
Code: [Select]
if %setimbue 15
  {
  set %clickx = xxx ;whatever the coordinate is
  set %clicky = xxx ;whatever the coordinate is
  gosub DoTheClick %clickx %clicky
  gosub DoTheClick %clickx %clicky
  }

Sub DoTheClick
  set %ClickmeX %1
  set %ClickmeY %2
  click %ClickmeX %ClickmeY
  ;insert some kind of gump waiting logic or gosub here
Return

X
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +786
  • Referrals: 1
    • View Profile
Re: Having a sub repeat x times
« Reply #4 on: January 25, 2010, 06:23:22 AM »
0
corrected your sysntax (if x = y ) and removed redundant lines (for %x Start End )

Code: [Select]
if %setimbue = 15
  {
  set %clicktimes 2
  gosub DoTheClick
  }

Sub DoTheClick
  for %i 0 %Clicktimes
     click %x %y
Return


You might also want to look at the click command parameters

click %x %y X , %ClickTimes

« Last Edit: January 25, 2010, 06:24:56 AM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline CoraginTopic starter

  • Wacko in Pajama's
  • Elite
  • *
  • *
  • Posts: 1641
  • Activity:
    0%
  • Reputation Power: 23
  • Coragin might someday be someone...Coragin might someday be someone...Coragin might someday be someone...Coragin might someday be someone...
  • Gender: Male
  • It Is What It Is.
  • Respect: +117
  • Referrals: 1
    • View Profile
Re: Having a sub repeat x times
« Reply #5 on: January 25, 2010, 07:23:36 AM »
0
EN and 12X, you guys are my heros for teaching me, you give such great examples, thank you.  Now maybe you can help me with what Im working on in special projects.  I will just post my questions here, since its all how to stuff...

Please give me some great examples....

1. How do I close a single gump with no exit button?  Paul tried to help me with this, but its not working.  Im doing something wrong.

Next question I know is redundant because I have asked about this like a zillion times, Im having a hard time remembering, small quote from the thread here...

Clicks...

I got it setup like this...

Code: [Select]
set %plantwaterx #contposx + 220
set %plantwatery #contposy + 75

With the click in the sub looking like this...(clicking a gump)

Code: [Select]
click %plantwaterx %plantwatery
gosub waitfortarget

Is this correct?  Because sometimes its clicking sometimes it isint.

Final question dealing with targeting an item, which I think I am doing something wrong...

Code: [Select]
  finditem %water C_ , %potionsecure
  set #ltargetid %water
      event macro 22 0

Now its not doing it for some reason.  For all potions and water I got the same thing, so if I can figure this out, I think I can get the script running, to test further.

Heres is what the whole sub looks like...

Code: [Select]
set %plantwaterx #contposx + 220
set %plantwatery #contposy + 75

Sub CheckWater
savePix %waterckx %watercky 1
wait 10
if ( #pixcol > %yellow1 )
{
if ( #pixcol < %yellow2 )
{
waterloop1:
gosub CheckWaterContainer
click %plantwaterx %plantwatery
gosub waitfortarget
  if ! #result
       goto waterloop1
  finditem %water C_ , %potionsecure
  set #ltargetid %water
      event macro 22 0
  wait 15
  gosub waitforgump %plantwindow1
}
}
if ( #pixcol > %red1 )
{
if ( #pixcol < %red2 )
{
waterloop2:
gosub CheckWaterContainer
click %plantwaterx %plantwatery
gosub waitfortarget
  if ! #result
       goto waterloop2
  finditem %water C_ , %potionsecure
  set #ltargetid %water
      event macro 22 0
  wait 15
  gosub waitforgump %plantwindow1
  gosub CheckWaterContainer
click %plantwaterx %plantwatery
gosub waitfortarget
  if ! #result
       goto waterloop2
  finditem %water C_ , %potionsecure
  set #ltargetid %water
      event macro 22 0
  wait 15
  gosub waitforgump %plantwindow1
}
}
Return

Ok, yes got one more, so I dont need to post again...

This is setting up potions, poison, heal ect, for the subs similar to the above...does it look correct?

Code: [Select]
Sub SetPotions
display OK Click on your workchest
        {
        set #targcurs 1
        while #targcurs = 1
              wait 1
        set %potionsecure #ltargetid
        set #lobjectID #ltargetID
        event macro 17 0
        wait 20
        set #menubutton N/A
        }
Display OK Click on your POISON Potions
        {
        set #targcurs 1
        while #targcurs =  1
              wait 1
        set %poisonpotions #ltargetid
        wait 10
        }
Display OK Click on your CURE Potions
        {
        set #targcurs 1
        while #targcurs = 1
              wait 1
        set %curepotions #ltargetid
        wait 10
        }
Display OK Click on your HEAL Potions
        {
        set #targcurs 1
        while #targcurs = 1
              wait 1
        set %healpotions #ltargetid
        wait 10
        }
Display OK Click on your STRENGTH Potions
        {
        set #targcurs 1
        while #targcurs = 1
              wait 1
        set %strengthpotions #ltargetid
        wait 10
        }
Return

Is that setting my potions properly?  OR should I just use finditem id/type and look at the property or color and cut that sub completely?

How do I reset all variables when the script starts?  Sometimes when I was trying to fix this, I would stop the script and restart it with new code to fix something and it would go straight to tending plants instead of going through menu and setup. 
Coragin

My Facebook
And now I'm better at doing what ever it is Wolverine does!

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +786
  • Referrals: 1
    • View Profile
Re: Having a sub repeat x times
« Reply #6 on: January 25, 2010, 10:28:24 AM »
0
1. How do I close a single gump with no exit button?  Paul tried to help me with this, but its not working.  Im doing something wrong.
Right click it - rember scripting emulates user action.. you close it the same way you manually would close it ...  Click x y R

Next question ...Is this correct?  Because sometimes its clicking sometimes it isint.

Yes the way you done it is correct.  But rember the script emulates what you yourself do.. their for if you did some action to load the gump prior to clicking it .. you yourself dont click until you can actually see the gump.. sometimes the gump loads slower than other times due to lag... thier for if your script does  use tool click... the gump might not be present when you click so you carnt click it.

you must use tool.. waitforgump... click..


Final question dealing with targeting an item, which I think I am doing something wrong...Now its not doing it for some reason.  For all potions and water I got the same thing, so if I can figure this out, I think I can get the script running, to test further.

Rember the results from a finditem command are held in the #findid  #findcol #findblablabla variables not in %water


This is setting up potions, poison, heal ect, for the subs similar to the above...does it look correct? Is that setting my potions properly?  OR should I just use finditem id/type and look at the property or color and cut that sub completely?

That looks fine.. a pain in the backside to click on the potions each time but it will work... for easier setup an auto find sub would be nicer but either work.



How do I reset all variables when the script starts?  Sometimes when I was trying to fix this, I would stop the script and restart it with new code to fix something and it would go straight to tending plants instead of going through menu and setup.  


Impossible really to say but off the bat .. all vars should be reset on start.
But if you dont think they are write a setup sub that sets all vars to thier starting value.. ie  set #menubutton N/a   This is good codeing technique anyhow.
« Last Edit: January 25, 2010, 10:30:16 AM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Tags: