View unanswered posts | View active topics It is currently Thu Apr 23, 2026 12:42 am



Reply to topic  [ 7 posts ] 
 How do you use Subroutines? 
Author Message
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post 
I use this one I use as part of an include to prevent script getting stuck after issuing a subspace command.
#:9_waittrigger~waittrigger
:waittrigger
killtrigger subspace0
killtrigger subspace1
killtrigger subspace2
settexttrigger subspace0 :subspace "Sub-space comm-link terminated"
settexttrigger subspace1 :subspace "sent on sub-space channel"
setdelaytrigger subspace2 :timeout 10000
pause
:subspace
killtrigger subspace0
killtrigger subspace1
killtrigger subspace2
return

_________________
Coconut Telegraph (ICQ)#586137616
Team Speak3@ 220.244.125.70:9987
Founding Member -=[Team Kraaken]=- Winner of Gridwars 2010 - Ka Pla
Image
Jesus wounldn't Subspace Crawl


Thu Feb 01, 2007 5:37 pm
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
That can be a bit confusing. He's doing...

gosub :waittrigger

The trigger to :subspace is not a subroutine, so the return is not exiting back to the trigger... it's exiting to the gosub call that is outside of this snippet.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Thu Feb 01, 2007 9:02 pm
Profile ICQ WWW
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post 
gosub :9_waittrigger~waittrigger actually but yes that is how its used.
Might be nice to see what other peeps have come up with and how they use subroutines.I find them of great help in error checking and keeping redundant code out of my scripts

_________________
Coconut Telegraph (ICQ)#586137616
Team Speak3@ 220.244.125.70:9987
Founding Member -=[Team Kraaken]=- Winner of Gridwars 2010 - Ka Pla
Image
Jesus wounldn't Subspace Crawl


Thu Feb 01, 2007 9:24 pm
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Hehe. Sure thing...

Code:
# Get the course
:get_course
   setVar $sectors ""

   # Wait for the course to start
   killtrigger timeout
   setDelayTrigger timeout :course_timeout 3000
   send "^ f *" & $destination & "**q"
   waitFor "  TO > "
   killtrigger timeout

   # Start reading the course
   killtrigger read_line
   killtrigger no_path_1
   killtrigger no_path_2
   killtrigger no_path_3
   setTextLineTrigger read_line :readline " > "
   setTextLineTrigger no_path_1 :no_path  "So what's the point?"
   setTextLineTrigger no_path_2 :no_path  ": ENDINTERROG"
   setTextLineTrigger no_path_3 :no_path  "No route within"
   pause

   # - - - - - - - - - - - - - - - - - - - - - - - -

   # No path...
   :no_path
      killtrigger read_line
      killtrigger no_path_1
      killtrigger no_path_2
      killtrigger no_path_3
      setVar $result "BAD"
      return

   # - - - - - - - - - - - - - - - - - - - - - - - -

   # Got a path
   :readline
   killtrigger read_line
   killtrigger no_path_1
   killtrigger no_path_2
   killtrigger no_path_3

   # Did we get the end line?
   getWord CURRENTLINE $endtest 2
   if ($endtest = "ENDINTERROG")
      goto oneline
   end

   # Append line
   setVar $sectors $sectors & " " & CURRENTLINE

   # Reset the trigger
   setTextLineTrigger read_line :readline ""
   pause

   # Done reading lines
   oneline
   killtrigger read_line

   # Clean up the sectors list
   striptext $sectors "("
   striptext $sectors ")"
   replacetext $sectors ">" " "

   # - - - - - - - - - - - - - - - - - - - - - - - -

   # Create the course array
   :create_course_array
   setVar $sectors $sectors & " %&%&%"
   setVar $course_length 0
   setVar $wordy ""
   setVar $word_to_read 1
   while ($wordy <> "%&%&%")
      getWord $sectors $wordy $word_to_read
      if ($wordy <> "%&%&%")
         add $course_length 1
         setVar $course[$course_length] $wordy
      end
      add $word_to_read 1
   end
return

:course_timeout
   killtrigger timeout
   setVar $result "BAD"
   return


Then all you have to do is...

Code:
setVar $destination 1234
gosub :get_course


And it gets the course as a neat little array, taking in account avoids w/o requiring a ztm.

One small example. I make extensive use of subroutines and includes.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Thu Feb 01, 2007 11:51 pm
Profile ICQ WWW
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post 
so to prevent redundant cycling in a colo script
Code:
setVar $destination 1234 
getcourse $course currentsector $destination 
if ($course = "-1") 
gosub :get_course
end

and your done,,,very nice

_________________
Coconut Telegraph (ICQ)#586137616
Team Speak3@ 220.244.125.70:9987
Founding Member -=[Team Kraaken]=- Winner of Gridwars 2010 - Ka Pla
Image
Jesus wounldn't Subspace Crawl


Fri Feb 02, 2007 1:19 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Yep. Keep in mind that getCourse won't handle avoids unless you set them and will mess up if you're using a partial ztm. That's why I tend to avoid getCourse if I don't absolutely need the speed, a cf plot is more accurate under a wider set of conditions.

If you're planning to colonize that means you'll want to clear your avoids first. Otherwise you'll get an inaccurate hopcount and end up taking the wrong amount of fuel. If you're using it as a lawnmow or gridder... then you need to build for the situation you're likely to be in.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Fri Feb 02, 2007 2:21 am
Profile ICQ WWW
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post 
i use a CF plot in my mower so I dont have to deal with the getcourse headache.I havent played with the internal voids in the new twx yet.

_________________
Coconut Telegraph (ICQ)#586137616
Team Speak3@ 220.244.125.70:9987
Founding Member -=[Team Kraaken]=- Winner of Gridwars 2010 - Ka Pla
Image
Jesus wounldn't Subspace Crawl


Fri Feb 02, 2007 3:13 am
Profile ICQ YIM
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 35 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.