Author Topic: repeat until or goto, which do you use?  (Read 3968 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: +57
  • Referrals: 1
    • View Profile
repeat until or goto, which do you use?
« on: February 07, 2010, 04:11:24 AM »
0
depending on if i can remember repeat until I use it, but for the most part I use goto loop and have the sub handle if it should return or stop.  I guess its pretty much the exact same thing just different wording.

like going from mi to ca, car vs bus, both will get you there, just car gives you more freedom over your time vs bus you have less to do besides sitting and waiting but it takes longer.
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: +321
  • Referrals: 2
    • View Profile
Re: repeat until or goto, which do you use?
« Reply #1 on: February 07, 2010, 04:50:14 AM »
0
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 Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: repeat until or goto, which do you use?
« Reply #2 on: February 07, 2010, 04:51:51 AM »
0
goto's are for losers. ;)
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

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: +57
  • Referrals: 1
    • View Profile
Re: repeat until or goto, which do you use?
« Reply #3 on: February 07, 2010, 05:08:26 AM »
0
I like if x goto y else 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: +162
  • Referrals: 1
    • View Profile
Re: repeat until or goto, which do you use?
« Reply #4 on: February 07, 2010, 11:14:03 AM »
0
I read the title of your post and opened it to see who flamed you for it.  I don't think you are done catching S@#$ for this one, but I do see the value in GoTo's, or at least I am not advanced enough to get around using them and therefore am still a loser.

The one use for them that I can't figure out a workaround for is for when I return a negative result from a gumpwait or target cursor wait and I need to go back to the beginning of a sub with multiple clicks like this one:


Code: [Select]
Sub SetCraftGump
      finditem %TinkersTools C_ , #BackpackID
      if #findcnt < 1
         {
         display Get a tinker tool in your backpack and hit play in the EUO window
         pause
         }
      if #findcnt < 2
         gosub MakeTinkersTools
      finditem %CurrentToolType C_ , #BackpackID
      if #findcnt < 2
         gosub MakeTwoTools
      CraftLoop:
      finditem %CurrentResource C_ , #BackpackID
      if #findstack < %CurrentResourceCnt
         Gosub MoveResources %CurrentResource %CurrentResourceCnt %ResourceSecure #BackpackID
      Finditem %CurrentToolType C_ , #backpackid
      Set #lobjectid #findid
      Event macro 17 0
            gosub waitforgump %cwin
            if ! #result
               Goto CraftLoop
      gosub offsetClick %CurrentResourceXClick1 %CurrentResourceYClick1
            gosub waitforgump %cwin
            if ! #result
               Goto CraftLoop
      gosub offsetClick %CurrentResourceXClick2 %CurrentResourceYClick2
            gosub waitforgump %cwin
            if ! #result
               Goto CraftLoop
      gosub offsetClick %CurrentItemxclick1 %CurrentItemyclick1
            gosub waitforgump %cwin
            if ! #result
               Goto CraftLoop
      gosub OffsetClick %CurrentItemxclick2 %CurrentItemyclick2
            gosub waitforgump %cwin
            if ! #result
               Goto CraftLoop
      If %xclick2 = 380
         {
         gosub OffsetClick %CurrentItemxclick3 %CurrentItemyclick3
               gosub waitforgump %cwin
               if ! #result
                  Goto CraftLoop
         }
Gosub OffsetClick 30 450
wait 5
Return

I can't think of an efficient way to replace the GoTo's in this sub.  However, I am willing to embrace my ignorance and learn from my betters if someone wants to teach me something...
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 Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: repeat until or goto, which do you use?
« Reply #5 on: February 07, 2010, 11:46:59 AM »
0
If it's a condition you can use while... like

while C in #charStatus
{
cast cure
wait 20
}

See, that will constantly check your #charStatus and keep casting cures until your not poisoned.

Whiles work great for stuff like that. Repeat/Until works better for stuff that needs to be checked.... like if your making something and you want to keep trying until you make it.

repeat
{
findItem XXX C_ , #backpackID.
make item XXX
}
until #findCnt > 0

That will keep making something until you have more then 0 of them in your pack.

You can use While the same as Repeat, but it really works best by itself when looking for a EUO condition flag.

goto's are just bad mojo... they lead to writing scripts that have you use them to exit gosubs... which is just bad form.
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

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: +162
  • Referrals: 1
    • View Profile
Re: repeat until or goto, which do you use?
« Reply #6 on: February 07, 2010, 01:02:55 PM »
0
Cerv, I don't mean to be a complete loser or to be annoying.  Like I tell my wife: I want to do things better, I just don't know how to fix the problem. What do you think of using them in the sub I posted?  Is there an alternative?
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 Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: repeat until or goto, which do you use?
« Reply #7 on: February 07, 2010, 01:05:11 PM »
0
I'll dig deeper into that at work ;)
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13305
  • Activity:
    0.6%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: repeat until or goto, which do you use?
« Reply #8 on: February 07, 2010, 01:09:20 PM »
0
Don't forget that 1.5 version of EUO also included the use of "break" and "continue" for the new looping constructs.
Please read the ScriptUO site RULES
Come play RIFT with me!

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: +393
  • Referrals: 1
    • View Profile
Re: repeat until or goto, which do you use?
« Reply #9 on: February 07, 2010, 05:23:43 PM »
0
paulo .. do the negative.. instead if ! #result goto blabla ..   do if #result do action .. until #result = #true

Code: [Select]
Sub SetCraftGump
      finditem %TinkersTools C_ , #BackpackID
      if #findcnt < 1
         {
         display Get a tinker tool in your backpack and hit play in the EUO window
         pause
         }
      if #findcnt < 2
         gosub MakeTinkersTools
      finditem %CurrentToolType C_ , #BackpackID
      if #findcnt < 2
         gosub MakeTwoTools
      repeat   ; CraftLoop
        finditem %CurrentResource C_ , #BackpackID
        if #findstack < %CurrentResourceCnt
           Gosub MoveResources %CurrentResource %CurrentResourceCnt %ResourceSecure #BackpackID
        Finditem %CurrentToolType C_ , #backpackid
        Set #lobjectid #findid
        Event macro 17 0
        gosub waitforgump %cwin
         if #result
           {
           gosub offsetClick %CurrentResourceXClick1 %CurrentResourceYClick1
           gosub waitforgump %cwin
            }
         if  #result
           {
           gosub offsetClick %CurrentResourceXClick2 %CurrentResourceYClick2
           gosub waitforgump %cwin
           }
         if  #result
           {
           gosub offsetClick %CurrentItemxclick1 %CurrentItemyclick1
           gosub waitforgump %cwin
           }
         if #result
           {
           gosub OffsetClick %CurrentItemxclick2 %CurrentItemyclick2
           gosub waitforgump %cwin
        if #result
           {
           If %xclick2 = 380
              {
             gosub OffsetClick %CurrentItemxclick3 %CurrentItemyclick3
             gosub waitforgump %cwin
             }
           }
  Until #result
  Gosub OffsetClick 30 450
  wait 5
Return



GOTOs are beyond evil.. if you can overcome using gotos you have a chance at creating real scripts.  Thats just my opinion thow.
« Last Edit: February 07, 2010, 05:25:32 PM 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."

Scrripty

  • Guest
Re: repeat until or goto, which do you use?
« Reply #10 on: February 07, 2010, 11:08:42 PM »
0
Or you could do a repeat..until and sub out the craft part I'm guessing.  So instead of a goto.. it's a gosub craftloop...? :)

Offline UOMaddog

  • Maddog
  • Elite
  • *
  • *
  • Posts: 1625
  • Activity:
    0%
  • Reputation Power: 22
  • UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...
  • Gender: Male
  • Biggest B@D@$$ of the Universe
  • Respect: +165
  • Referrals: 8
    • View Profile
    • Insane UO
Re: repeat until or goto, which do you use?
« Reply #11 on: February 08, 2010, 11:42:13 AM »
0
This has always been my understanding of goto's:

NEVER use a goto! LoL

Anyways, the main reason is due to reliability of code. There are ways of mathematically "proving" code to be perfect (error-free) and goto's violate the math required (it's like trying to divide by zero). Granted, none of us are working as programmers for Solaris or anything like that, but it's still a good habit to have!

Most of the goto's used in scripts on this site are harmless and will not cause issues, but it's just one of those things that is SOOO easily avoided by using other methods that it just shouldn't be used. If anyone does not know how to get around using a goto, just ask and you'll learn a lot when you see the answer! Scripting is 90% preparatory thought and 10% typing correctness! LOL  ;D
There are 10 kinds of people in this world: those that understand binary and those that don't!

Windows:  A 64-bit tweak of a 32-bit extension to a 16-bit user interface for an 8-bit operating system based on a 4-bit architecture from a 2-bit company that can't stand 1 bit of competition!

Tags: