View unanswered posts | View active topics It is currently Tue Apr 21, 2026 2:26 pm



Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4
 Script Challenge - Amtrak 
Author Message
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: Script Challenge - Amtrak
Good question Maniac. I established in my first post that the starting sector is Stardock. Since the first destination is Terra, the first MSL to be walked will be from SD to Terra.

Now, that may not be the best way to get it done, and you certainly don't have to do it that way. But when you start thinking of ways to shorten a script, creating a word list and iterating over it can make for some very concise code. This was the way that made the most sense to me.

LS, you have a valid point about the ZTM, and I didn't mention it. Assume that the warp data in TWX is complete, and that the TWX database can be queried reliably. So use functions like getCourse and SECTOR.WARPS as often as possible to shave a few lines.

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Wed Feb 10, 2010 11:40 pm
Profile WWW
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post Re: Script Challenge - Amtrak
ElderProphet wrote:
Good question Maniac. I established in my first post that the starting sector is Stardock. Since the first destination is Terra, the first MSL to be walked will be from SD to Terra.

Now, that may not be the best way to get it done, and you certainly don't have to do it that way. But when you start thinking of ways to shorten a script, creating a word list and iterating over it can make for some very concise code. This was the way that made the most sense to me.

LS, you have a valid point about the ZTM, and I didn't mention it. Assume that the warp data in TWX is complete, and that the TWX database can be queried reliably. So use functions like getCourse and SECTOR.WARPS as often as possible to shave a few lines.


You realize this won't be an useable script. Its just an exercise. So use whatever produces interesting code.

_________________
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 11, 2010 12:50 am
Profile ICQ YIM
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: Script Challenge - Amtrak
I'm confident that an 11 or 14 line amtrak will be useless outside of this exercise, yes. But the exercise itself is far from useless. I've already learned new insights into TWX scripting... and frankly, I'm surprised. Let me list a few of these.

I think Sing's example of recursion is incredible. His example moves down a target list, $targets, appending to it as it goes. As originally posted, it would mistakenly grid the whole universe, oops, but a brilliant solution. He said, "Just create a list of sectors to grid, then grid them." I said, "That's 2 while loops, too many lines." He said, "I think I can do it in less."

I just realized during this challenge that write, and readToArray can be used to create an array very effectively. Promethius posted an example using this technique.

I've learned that the command 'branch' can be useful for combining nested while loops, possibly. For example, if you have this while structure:
Code:
setVar $a 1
while ($a <= 10)
   setVar $b 1
   while ($b <= 5)
      setVar $c 1
      while ($c <= 2)
         echo $a "." $b "." $c "*"
         add $c 1
      end
      add $b 1
   end
   add $a 1
end
You can write it with this functionally equivalent code:
Code:
setVar $a 1
setVar $b 1
setVar $c 1
:loop
      echo $a "." $b "." $c "*"
      add $c 1
      branch ($c > 2) :loop
   setVar $c 1
   add $b 1
   branch ($b > 5) :loop
setVar $b 1
add $a 1
branch ($a > 10) :loop

So, you slackers that haven't given this a shot yet, jump on in, and learn something new.

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Thu Feb 11, 2010 6:58 pm
Profile WWW
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: Script Challenge - Amtrak
Nice readToArray trick. With that, can we get (in 2.05) a way to populate an array from a line? setVar $array[] (1,2,3,4,5,6), for instance?

_________________
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 11, 2010 8:19 pm
Profile ICQ WWW
Display posts from previous:  Sort by  
Reply to topic   [ 49 posts ]  Go to page Previous  1, 2, 3, 4

Who is online

Users browsing this forum: No registered users and 24 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.