View unanswered posts | View active topics It is currently Wed Apr 22, 2026 3:11 am



Reply to topic  [ 69 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
 Scripting Challenge 
Author Message
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Mind Dagger wrote:
LoneStar wrote:
okay. my very last submision. 18 Lines:

...

[EDIT] I Lied. Previous 'final' version was 20 Lines.. this is now at 18


Hey Lone, you were wrong. You take out one unneeded label and you are actually at 17

Code:
send "/"
waitfor #179
:ScanLine
if (CURRENTLINE <> "")
     setVar $Result ($Result & " " & CURRENTLINE)
     setTextLineTrigger ScanLine2 :ScanLine
     pause
end
ReplaceText $Result #179 " "
StripText $Result ","
getWord $Result $Temp ($i + 2)
While ($Temp <> 0)
     upperCase $Temp
     getWord $Result $Stat[$Temp] ($i + 1)
     add $i 2
     getWord $Result $Temp $i
end


Hey Wow.. Thanks MD! I just gave up on getting 16 lines..laff. here's what I was working on.. running it might put twx into an infinite Loop:
Code:
send "/"
waitfor #179
:ScanLine
if (CURRENTLINE <> "")
     setVar $Result ($Result & #179 & CURRENTLINE)
     setTextLineTrigger ScanLine2 :ScanLine
     pause
end
StripText $Result ","
getWord $Result $Temp 2
While ($Temp <> "")
     setVar $Holding $Temp
     upperCase $Temp
     getText $Result $Stat[$Temp] ($Holding&" ") #179
     getText $Result $Temp ($Stat[$Temp] & #179) " "
end

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Mon Jun 04, 2007 8:44 pm
Profile ICQ YIM
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
okay. I think MD and I should get credit for this.. hehe.. the Bar has been Raised (or lowered) to 14!!
Code:
send "^/q"
waitfor #179
while (CURRENTLINE <> ": ENDINTERROG")
     setVar $Result ($Result & " " & CURRENTLINE)
     waitFor " "
end
ReplaceText $Result #179 " "
StripText $Result ","
UpperCase $Result
While ($i <= 60)
     add $i 2
     getWord $Result $Temp $i
     getWord $Result $Stat[$Temp] ($i + 1)
end

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Mon Jun 04, 2007 9:09 pm
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Quote:
I knew this would come up. the Default for accessing an un initialized Dynamic Array elemtent is... Drum Roll... ZERO


That's true only if the data has never been set before. But a system script where someone drops corp would have ghost data to deal with. That's why I almost always preset my vars, it makes code more portable.

Fortunately this can be done with a single line:

Code:
setArray $quickstats 0
send "^/q"
waitfor #179
while (CURRENTLINE <> ": ENDINTERROG")
     setVar $line $line & " " & CURRENTLINE
     waitFor " "
end
replaceText $line #179 " "
stripText $line ","
upperCase $line
while ($stat <> "%%%")
     add $i 2
     getWord $line $stat $i "%%%"
     getWord $line $quickstats[$stat] ($i+1) "%%%"
     if ($stat = "SHIP")
           getWord $line $quickstats[TYPE] ($i+2)
     end
end


That's obviously based on MD's, but I use the default word setting instead of $i <= 60, and it adds shiptype processing. I wonder what the shortest way of processing shiptype is.

_________________
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


Mon Jun 04, 2007 11:09 pm
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Singularity wrote:
Quote:
I knew this would come up. the Default for accessing an un initialized Dynamic Array elemtent is... Drum Roll... ZERO


That's true only if the data has never been set before. But a system script where someone drops corp would have ghost data to deal with. That's why I almost always preset my vars, it makes code more portable.


I'm confused. I thought the challenge was for shortest *Routine* and here we are talking about Sub Routines, that by deffiinition absolutely require Local Variable Initialization to a *Known* value, in anticipation of subsequent function calls.

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Tue Jun 05, 2007 12:59 am
Profile ICQ YIM
Lieutenant J.G.

Joined: Fri Apr 05, 2002 3:00 am
Posts: 332
Location: USA
Unread post 
Okay if what I understand of the scripting language from reading your scripts is right, there's either a minor bug in the program or you can shorten it a tiny bit.
Question, is ship always the last thing listed in the quickstats?  If so, you can easily eliminate the ship check if loop like so:
Code:
setArray $quickstats 0
send "^/q"
waitfor #179
while (CURRENTLINE <> ": ENDINTERROG")
     setVar $line $line & " " & CURRENTLINE
     waitFor " "
end
replaceText $line #179 " "
stripText $line ","
upperCase $line
while ($stat <> "%%%")
     add $i 2
     getWord $line $stat $i "%%%"
     getWord $line $quickstats[$stat] ($i+1) "%%%"
end
getWord $line $quickstats[TYPE] ($i-2)

(Edit: Not sure about that last line, but if the logic works the way I understand it to, you'd walk 2 spaces beyond your ship's name before breaking out of the while, so you'd assign $i-2 to TYPE.  I haven't looked at any documentation of this language, just basing everything on the examples I see here, so correct me if I'm wrong.)
If ship is NOT always last, then there's a bug in the script as originally posted, because you assign i+2 to type but only jump two spaces ahead for the next iteration of the white loop, meaning you create a stat named <shipname> and assign the next stat name to the MerFre stat (or whatever ship you're in).  In that case, you'd have to change it to this:
Code:
setArray $quickstats 0
send "^/q"
waitfor #179
while (CURRENTLINE <> ": ENDINTERROG")
     setVar $line $line & " " & CURRENTLINE
     waitFor " "
end
replaceText $line #179 " "
stripText $line ","
upperCase $line
while ($stat <> "%%%")
     add $i 2
     getWord $line $stat $i "%%%"
     getWord $line $quickstats[$stat] ($i+1) "%%%"
     if ($stat = "SHIP")
           getWord $line $quickstats[TYPE] ($i+2) 
            add $i 1
     end
end

The first (assuming ship is the last stat listed) saves 2 lines, the latter adds a line to correct for the bad i offset in the next loop.

_________________
Creator of the TWGS Data Access Library
http://twgs.xiuhtec.com


Tue Jun 05, 2007 1:15 am
Profile ICQ YIM
Chief Warrant Officer
User avatar

Joined: Wed Jan 04, 2006 3:00 am
Posts: 136
Location: USA
Unread post 
This is probably the shortest way to grab ship type:

Code:
setArray $quickstats 0
send "^/q"
waitfor #179
while (CURRENTLINE <> ": ENDINTERROG")
     setVar $line $line & " " & CURRENTLINE
     waitFor " "
end
replaceText $line #179 " "
stripText $line ","
upperCase $line
while ($stat <> "%%%")
     add $i 2
     getWord $line $stat $i "%%%"
     getWord $line $quickstats[$stat] ($i+1) "%%%"
     getWord $line $quickstats[TYPE] ($i+2)
     end
end


Edit: Turns out Xentropy and I had roughly the same idea. And posted it almost at the same time too.


Tue Jun 05, 2007 1:16 am
Profile
Lieutenant J.G.

Joined: Fri Apr 05, 2002 3:00 am
Posts: 332
Location: USA
Unread post 
LoneStar wrote:
Singularity wrote:
Quote:
I knew this would come up. the Default for accessing an un initialized Dynamic Array elemtent is... Drum Roll... ZERO


That's true only if the data has never been set before. But a system script where someone drops corp would have ghost data to deal with. That's why I almost always preset my vars, it makes code more portable.


I'm confused. I thought the challenge was for shortest *Routine* and here we are talking about Sub Routines, that by deffiinition absolutely require Local Variable Initialization to a *Known* value, in anticipation of subsequent function calls.

Um, what he's saying is this script obviously isn't intended to run in a vacuum.  There'd be no point whatsoever in running this routine and then doing nothing with the data, and never running the routine again later.  In that case, if you ran the routine once while in a corporation, you'd set the CORP stat to your corp#.  If you then ran it after leaving your corp, it'd never reset the CORP stat so it'd still think you're in that corp.

_________________
Creator of the TWGS Data Access Library
http://twgs.xiuhtec.com


Tue Jun 05, 2007 1:22 am
Profile ICQ YIM
Lieutenant J.G.

Joined: Fri Apr 05, 2002 3:00 am
Posts: 332
Location: USA
Unread post 
Mind Dagger wrote:
This is probably the shortest way to grab ship type:

Code:

setArray $quickstats 0
send "^/q"
waitfor #179
while (CURRENTLINE <> ": ENDINTERROG")
     setVar $line $line & " " & CURRENTLINE
     waitFor " "
end
replaceText $line #179 " "
stripText $line ","
upperCase $line
while ($stat <> "%%%")
     add $i 2
     getWord $line $stat $i "%%%"
     getWord $line $quickstats[$stat] ($i+1) "%%%"
     getWord $line $quickstats[TYPE] ($i+2)
end


Edit: Turns out Xentropy and I had roughly the same idea. And posted it almost at the same time too.

Your idea was better IF the loop breaks before assigning null values after it falls off the end of the string.  If it assigns blank values to blank statnames at the end, you'd end up with a blank TYPE value as well.  Again I ask how the logic works exactly and what the while loop is doing.
Edit: In fact, if it's doing what I think it's doing, you'd have to pull the TYPE assignment out of the while loop and assign $i-2.  Because you'd get one last while loop run to assign null to $quickstats[YOURSHIPNAME] before finally getting into the loop where $i doesn't exist and it puts "%%%" in $stat instead.  So you'd be 2 spaces *beyond* the shipname by the time the loop ended, and would assign $i-2 to TYPE.  It'd run a tiny bit faster with that assignment outside the loop, too, as you'd save assigning meaningless dummy values to STAT i/2 times.

_________________
Creator of the TWGS Data Access Library
http://twgs.xiuhtec.com


Tue Jun 05, 2007 1:24 am
Profile ICQ YIM
Chief Warrant Officer
User avatar

Joined: Wed Jan 04, 2006 3:00 am
Posts: 136
Location: USA
Unread post 
Xentropy wrote:
Mind Dagger wrote:
This is probably the shortest way to grab ship type:
Code:
setArray $quickstats 0 send "^/q" waitfor #179 while (CURRENTLINE <> ": ENDINTERROG")      setVar $line $line & " " & CURRENTLINE      waitFor " " end replaceText $line #179 " " stripText $line "," upperCase $line while ($stat <> "%%%")      add $i 2      getWord $line $stat $i "%%%"      getWord $line $quickstats[$stat] ($i+1) "%%%"      getWord $line $quickstats[TYPE] ($i+2) end
Edit: Turns out Xentropy and I had roughly the same idea. And posted it almost at the same time too.

Your idea was better IF the loop breaks before assigning null values after it falls off the end of the string. If it assigns blank values to blank statnames at the end, you'd end up with a blank TYPE value as well. Again I ask how the logic works exactly and what the while loop is doing.
Edit: In fact, if it's doing what I think it's doing, you'd have to pull the TYPE assignment out of the while loop and assign $i-2. Because you'd get one last while loop run to assign null to $quickstats[YOURSHIPNAME] before finally getting into the loop where $i doesn't exist and it puts "%%%" in $stat instead. So you'd be 2 spaces *beyond* the shipname by the time the loop ended, and would assign $i-2 to TYPE. It'd run a tiny bit faster with that assignment outside the loop, too, as you'd save assigning meaningless dummy values to STAT i/2 times.


You are absolutely right, nice catch.


Tue Jun 05, 2007 1:32 am
Profile
Chief Warrant Officer
User avatar

Joined: Wed Jan 04, 2006 3:00 am
Posts: 136
Location: USA
Unread post 
Fixed code:
Credit to Xentropy for the fix

Code:
setArray $quickstats 0
send "^/q"
waitfor #179
while (CURRENTLINE <> ": ENDINTERROG")
     setVar $line $line & " " & CURRENTLINE
     waitFor " "
end
replaceText $line #179 " "
stripText $line ","
upperCase $line
while ($stat <> "%%%")
     add $i 2
     getWord $line $stat $i "%%%"
     getWord $line $quickstats[$stat] ($i+1) "%%%"
end
getWord $line $quickstats[TYPE] ($i-2)



Tue Jun 05, 2007 1:38 am
Profile
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Xentropy wrote:
Um, what he's saying is this script obviously isn't intended to run in a vacuum.  There'd be no point whatsoever in running this routine and then doing nothing with the data, and never running the routine again later.  In that case, if you ran the routine once while in a corporation, you'd set the CORP stat to your corp#.  If you then ran it after leaving your corp, it'd never reset the CORP stat so it'd still think you're in that corp.


Um, again. Challenge: Shortest Routine    ...not shortest Script, not Shortest Sub Routine.

Since people insist on splitting hairs. Add the variable intialization lines.. MD still has the shortest routine. Isn't that the point of this Thread??

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Tue Jun 05, 2007 1:39 am
Profile ICQ YIM
Lieutenant J.G.

Joined: Fri Apr 05, 2002 3:00 am
Posts: 332
Location: USA
Unread post 
routine - " a sequence of computer instructions for performing a particular task"
That doesn't to me remove the requirement that the routine plays well with others and isn't expected to run in a vacuum.   Anyway, it's one line, so it doesn't matter much either way.  I just agree with Singularity on this one, as I'd always design a script with the expectation of the output actually being read somewhere later.
Hmm, I started to wonder why you guys were bothering to combine the lines of data into one line, but even removing that part of the logic didn't save any lines of code, so you may as well.  Unless you can perform steps like stripText on CURRENTLINE, which I'm guessing not since CURRENTLINE is game text and is probably constant.  If you can manipulate CURRENTLINE as if it were a variable and save the assignment to $line, you might be able to save a line of code by avoiding the line-combination step.
How do you know when you've reached the next line?  I assume the waitFor " " does this in some way, but there are lots of spaces in each individual line; does waitFor only trigger once per line max?

_________________
Creator of the TWGS Data Access Library
http://twgs.xiuhtec.com


Tue Jun 05, 2007 1:49 am
Profile ICQ YIM
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post 
Excellent code thus far. I have about (6) 15 line routines... but i've only succeeded once... maybe twice in creating sub 15-line routines. But let's not call it quits just yet. I want to add a couple of reasonable requirements...

Commas have to be stripped out.
The resulting array has to correctly reflect the 28 key stats.
The code has to be repeatable.

So it can't be written to only function once, but rather function for subsequent calls as well. This can add quite a few lines... resetting variables like $result and $i and what not become costly. Let me sum it up another way. Write it as though it were a subroutine, preceeded by a label, like :getStatSub, and finished up with a Return. In fact, let's post the routines that way, but those two lines are free, and don't apply to the count.

Let's not include the ship type as a requirement. The [Ship] index can be just the ship number, but including the name with it (as in "2 Merf" or "2Merf") counts as a bonus in the event of a tie.

Likewise for initializing the [Corp] and [Phot] stats to zero if they don't exist... that its a bonus in the event of a tie.

And a final bonus for having only the 28 stats in the array when complete. It isn't a penalty for having $quickStat[MerFre], but a tie can be broken by not having it in the array.

Really good turnout thus far... keep it up.

+EP+

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


Tue Jun 05, 2007 1:57 am
Profile WWW
Chief Warrant Officer
User avatar

Joined: Wed Jan 04, 2006 3:00 am
Posts: 136
Location: USA
Unread post 
I haven't read all your new requirements EP, but I just finished this 12 liner, so I wanted to post it quick.

Code:
:quikstats
     setArray $quickstats 0
     setVar $i 0
     send "/" & #145
     waitfor #145 & #8
     getText RAWPACKET $line "Sect" #145
     replaceText $line #179 " "
     stripText $line ","
     upperCase $line
     while ($stat <> "%%%")
           add $i 2
           getWord "SPACER SECT"&$line $stat $i "%%%"
           getWord "SPACER SECT"&$line $quickstats[$stat] ($i+1) "%%%"
     end
return


Edit: Changed it so it sent #145 instead
Edit: Added initialized $i per new requirements. 13 lines now.
Edit: Formatted code to look nicer and added sub label and return


Tue Jun 05, 2007 2:27 am
Profile
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Mind Dagger wrote:
I haven't read all your new requirements EP, but I just finished this 12 liner, so I wanted to post it quick.

Code:
setArray $quickstats 0
setVar $i 0
send "/" & #145
waitfor #145 & #8
getText RAWPACKET $line "Sect" #145
replaceText $line #179 " "
stripText $line ","
upperCase $line
while ($stat <> "%%%")
     add $i 2
     getWord "SPACER SECT"&$line $stat $i "%%%"
     getWord "SPACER SECT"&$line $quickstats[$stat] ($i+1) "%%%"
end


Edit: Changed it so it sent #145 instead
Edit: Added initialized $i per new requirements. 13 lines now.


Wow MD. Really nice.

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Tue Jun 05, 2007 2:52 am
Profile ICQ YIM
Display posts from previous:  Sort by  
Reply to topic   [ 69 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

Who is online

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