Official ScriptUO EasyUO Scripts > Scripting Chat

Looping without GoTo

(1/5) > >>

12TimesOver:
Just a quick one here.

In the quest for learning alternative methods for setting up loops within my scripts without the use of GoTo statements (just a personal quest to enhance my creative thinking) I wondered if the following example is syntacticly accurate in it's use of the #RETURN sysvar preloaded with a value. I've done this before with my own user vars but just wondered what other people thought about this as a general practice.

This example uses TM's Gumpwait sub which returns #FALSE if the timeout value is reached before the Gump is found.


--- Code: ---   set #RESULT #FALSE
   while #RESULT = FALSE
      {
      set #lobjectid %Container
      event macro 17
      gosub GumpWait Generic_Gump Generic_Gump
      finditem %ItemInContainer
      if #findkind <> 1
         set #RESULT #FALSE
      else set #RESULT #TRUE
      }
--- End code ---

Thanks for your input!

XII

TrailMyx:
Hmm, well I think you are kinda "over-writing" the intention of the return value for GumpWait since you aren't really using it now in this context.  So I think there's some unintended consequences to your usage.

With that said, I have used the #RESULT variable for general purposes many times; sometimes I just don't want to create a variable in a quicky sub, i.e.:


--- Code: ---;------------------------------------------------------------
sub TM_GetPersistantVariable
  set #RESULT %1 , _ , #CHARID
  set #RESULT * . #RESULT
return #RESULT
;------------------------------------------------------------
sub TM_SetPersistantVariable
  set #RESULT %1 , _ , #CHARID
  set * . #RESULT %2
return

--- End code ---

Personally, I get a chuckle out of people who will jump through no end of hoops to rid themselves of goto's and tags.  Oh, *chuckes*

12TimesOver:

--- Quote from: TrailMyx on October 31, 2008, 11:37:16 AM ---Hmm, well I think you are kinda "over-writing" the intention of the return value for GumpWait since you aren't really using it now in this context.  So I think there's some unintended consequences to your usage.

With that said, I have used the #RESULT variable for general purposes many times; sometimes I just don't want to create a variable in a quicky sub, i.e.:

<snip>

Personally, I get a chuckle out of people who will jump through no end of hoops to rid themselves of goto's and tags.  Oh, *chuckes*

--- End quote ---

Hehe, yeah that wasn't really a good example since I probably wouldn't be reopening a bag when a #finditem failed. I was just more concerned with the concept or syntax itself than the logic. Sounds like I'm not breaking any laws then.

As for the goto thing, well I'm just really trying to understand both sides and trying to think about things in more than one way. It really is more of a learning exercise for me than simply an evil goto statement remove activity. Personally I always get a feeling that I'm being inefficient when I pre-load a variable for a loop constraint just for the sake of loading the variable rather than as an activity of some other  logic within the program.

Did that make sense?

XII

Cerveza:
GOTO - Bad  >:(

While - Good  :D

Repeat/Until - Good  ;D

TrailMyx:
Wow, I'm surprised it took you so long Cerveza!  heh

Navigation

[0] Message Index

[#] Next page

Go to full version