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



Reply to topic  [ 69 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
 Scripting Challenge 
Author Message
Lieutenant J.G.

Joined: Fri Apr 05, 2002 3:00 am
Posts: 332
Location: USA
Unread post 
To fix the wasted assignment of the shipname to null (still 13 lines but leaves the loop one iteration sooner):
Code:

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

Only way I could figure out in this damndable language to implement a do/while LOL..
Edit: Removed now-unnecessary default "%%%" assignments.
Edit2: Initialized $i to -2 so I could remove the confusing "SPACER" stuff from the loop.  Just improves readability without affecting performance or length.
Edit3: Changed $i to -1... wouldn't the original, and with it initialized to -2, cause everything to be off by one?  Isn't the first word in the string, SECT, $i = 1, not $i = 2?  I may be wrong...

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


Tue Jun 05, 2007 3:11 am
Profile ICQ YIM
Lieutenant J.G.

Joined: Fri Apr 05, 2002 3:00 am
Posts: 332
Location: USA
Unread post 
LOL it seems a little "dirty" but can't you drop it to 11 by doing this?
Code:
:quikstats
     setArray $quickstats 0
     send "/" & #145
     waitfor #145 & #8
     getText RAWPACKET $line "Sect" #145
     stripText $line ","
     upperCase $line
     :addstat
     getWord $line $stat 1
     getText $line $quickstats[$stat] $stat&" " #179
     stripText $line $stat&" "&$quickstats[$stat]&#179
     branch ($stat <> "SHIP") :addstat
return 

You don't have to convert the #179's to spaces (saving one line) nor track or initialize an integer (saving two more lines), but you add one line to strip the data as you mine it.  Basically $line always has the next data to mine at the front.  Yes/no?
Edit: Doh, nevermind, won't work.  It won't work between one line and the next because there are no #179's at the ends of lines... Thought it was a good idea.
Edit2: A little less radical; still converts #179's to spaces, but still uses the "delete the data as you store it" method to avoid initializing and incrementing an integer:
Code:
:quikstats
     setArray $quickstats 0
     send "/" & #145
     waitfor #145 & #8
     getText RAWPACKET $line #179 #145
     replaceText $line #179 " "
     stripText $line ","
     upperCase $line
     :addstat
     getWord $line $stat 1
     getWord $line $quickstats[$stat] 2
     stripText $line $stat&" "&$quickstats[$stat]&" "
     branch ($stat <> "SHIP") :addstat
return 

12 lines.  Should work.
Edit: Noticed how the RAWPACKET was being parsed and fixed a bug by getting 2nd and 3rd words each time instead of 1st and 2nd.  I know it doesn't follow the rules by skipping sector data, but I'm too lazy to figure out how to fix that, and since any sane person is going to use CURRENTSECTOR and not a quickstats routine to get their current sector information I honestly fail to see the point of storing that part.
Edit2: And as long as I'm ignoring sect, changed the parsing to capture packet data starting at #179 and went back to 1st and 2nd word.  Last edit for tonight, I need sleep.

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


Tue Jun 05, 2007 3:39 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Using RAWPACKET wouldn't work if the data is spread over multiple packets... which it might be. You can't predict fragmentation. How would you handle that? Or does rawpacket handle that somehow?

_________________
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


Tue Jun 05, 2007 4:50 am
Profile ICQ WWW
Lieutenant J.G.

Joined: Fri Apr 05, 2002 3:00 am
Posts: 332
Location: USA
Unread post 
If RAWPACKET isn't reliable, my last idea goes up to 14 lines but parses SECT again.  Can easily go back to using |'s to separate data that way by explicitly adding #179's to the end of each line.
Code:
:quikstats
     setArray $quickstats 0
     send "^/q"
     waitfor #179
     while (CURRENTLINE <> ": ENDINTERROG")
          setVar $line $line & " " & CURRENTLINE & #179
          waitFor " "
     end
     stripText $line ","
     upperCase $line
     :addstat
     getWord $line $stat 1
     getText $line $quickstats[$stat] $stat&" " #179
     stripText $line $stat&" "&$quickstats[$stat]&#179
     branch ($stat <> "SHIP") :addstat
return 

The result of a lot of good collaborative work.  And my noob-ass screwing with good collaborative work.
Okay, really going to sleep this time, I promise.  Work is going to suck tomorrow on low sleep. LOL

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


Tue Jun 05, 2007 5:03 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:
If RAWPACKET isn't reliable, my last idea goes up to 14 lines but parses SECT again. Can easily go back to using |'s to separate data that way by explicitly adding #179's to the end of each line.
Code:
:quikstats      setArray $quickstats 0      send "^/q"      waitfor #179      while (CURRENTLINE <> ":  ENDINTERROG")         ;   setVar $line $line & " " & CURRENTLINE &  #179         &n bsp;waitFor "  "      end   &n bsp;  stripText $line ","      upperCase  $line      :addstat   ;   getWord $line $stat 1     getText $line $quickstats[$stat] $stat&" " #179     stripText $line $stat&" "&$quickstats[$stat]³     branch ($stat <> "SHIP") :addstatreturn 

The result of a lot of good collaborative work. And my noob-ass screwing with good collaborative work.
Okay, really going to sleep this time, I promise. Work is going to suck tomorrow on low sleep. LOL


Nice work on the code. Some great ideas in there. I tweaked it a little in order to get it running as well as take care of some formatting issues.

Code:
:quikstats
     setArray $quickstats 0
     send "^/q"
     waitfor #179
     while (CURRENTLINE <> ": ENDINTERROG")
           setVar $line CURRENTLINE & #179
           stripText $line ","
           upperCase $line
           :addstat
              getWord $line $stat 1 "%%%"
              getText $line $quickstats[$stat] $stat&" " #179
               stripText $line $stat&" "&$quickstats[$stat]³
              striptext $quickstats[$stat] " "
       branch ($stat = "%%%") :addstat
           waitFor " "
     end
return 


Tue Jun 05, 2007 5:46 am
Profile
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Xentropy wrote:
Code:
:quikstats      setArray $quickstats 0      send "^/q"      waitfor #179      while (CURRENTLINE <> ": ENDINTERROG")           setVar $line $line & " " & CURRENTLINE & #179          waitFor "  "      end   &n bsp;  stripText $line ","      upperCase  $line      :addstat   ;   getWord $line $stat 1     getText $line $quickstats[$stat] $stat&" " #179     stripText $line $stat&" "&$quickstats[$stat]³     branch ($stat <> "SHIP") :addstatreturn 

The result of a lot of good collaborative work.  And my noob-ass screwing with good collaborative work.
Okay, really going to sleep this time, I promise.  Work is going to suck tomorrow on low sleep. LOL


oh geeze... sorry to split hairs on you.. but your routine should actually work or is that not a prerequisite for this challenge? ...run this bit of code and see what I mean:

Code:
gosub :quiker_stats
Echo "*" & ANSI_15 & "Sect   = " & ANSI_14 & $quickstats[Sect] & "."
Echo "*" & ANSI_15 & "Turns  = " & ANSI_14 & $quickstats[Turns] & "."
Echo "*" & ANSI_15 & "Creds  = " & ANSI_14 & $quickstats[Creds] & "."
Echo "*" & ANSI_15 & "Figs   = " & ANSI_14 & $quickstats[Figs] & "."
Echo "*" & ANSI_15 & "Shlds  = " & ANSI_14 & $quickstats[Shlds] & "."
Echo "*" & ANSI_15 & "Hlds   = " & ANSI_14 & $quickstats[Hlds] & "."
Echo "*" & ANSI_15 & "Ore    = " & ANSI_14 & $quickstats[Ore] & "."
Echo "*" & ANSI_15 & "Org    = " & ANSI_14 & $quickstats[Org] & "."
Echo "*" & ANSI_15 & "Equ    = " & ANSI_14 & $quickstats[Equ] & "."
Echo "*" & ANSI_15 & "Col    = " & ANSI_14 & $quickstats[Col] & "."
Echo "*" & ANSI_15 & "Phot   = " & ANSI_14 & $quickstats[Phot] & "."
Echo "*" & ANSI_15 & "Armd   = " & ANSI_14 & $quickstats[Armd] & "."
Echo "*" & ANSI_15 & "Lmpt   = " & ANSI_14 & $quickstats[Lmpt] & "."
Echo "*" & ANSI_15 & "GTorp  = " & ANSI_14 & $quickstats[GTorp] & "."
Echo "*" & ANSI_15 & "TWarp  = " & ANSI_14 & $quickstats[TWarp] & "."
Echo "*" & ANSI_15 & "Clks   = " & ANSI_14 & $quickstats[Clks] & "."
Echo "*" & ANSI_15 & "Beacns = " & ANSI_14 & $quickstats[Beacns] & "."
Echo "*" & ANSI_15 & "AtmDt  = " & ANSI_14 & $quickstats[AtmDt] & "."
Echo "*" & ANSI_15 & "Crbo   = " & ANSI_14 & $quickstats[Crbo] & "."
Echo "*" & ANSI_15 & "EPrb   = " & ANSI_14 & $quickstats[EPrb] & "."
Echo "*" & ANSI_15 & "MDis   = " & ANSI_14 & $quickstats[MDis] & "."
Echo "*" & ANSI_15 & "PsPrb  = " & ANSI_14 & $quickstats[PsPrb] & "."
Echo "*" & ANSI_15 & "PlScn  = " & ANSI_14 & $quickstats[PlScn] & "."
Echo "*" & ANSI_15 & "LRS    = " & ANSI_14 & $quickstats[LRS] & "."
Echo "*" & ANSI_15 & "Aln    = " & ANSI_14 & $quickstats[Aln] & "."
Echo "*" & ANSI_15 & "Exp    = " & ANSI_14 & $quickstats[Exp] & "."
Echo "*" & ANSI_15 & "Corp   = " & ANSI_14 & $quickstats[Corp] & "."
Echo "*" & ANSI_15 & "Ship   = " & ANSI_14 & $quickstats[Ship] & "."
Echo "**"
halt
:quiker_stats
    setArray $quickstats 0
     send "^/q"
     waitfor #179
     while (CURRENTLINE <> ": ENDINTERROG")
                 setVar $line $line & " " & CURRENTLINE & #179
                 waitFor " "
     end
     stripText $line ","
     upperCase $line
     While ($stat <> "SHIP")
     getWord $line $stat 1
     getText $line $quickstats[$stat] $stat&" " #179
     stripText $line $stat&" "&$quickstats[$stat]³
     end
     return

I had to remove the Branch thing because it otherwise wouldn't work --for me at least. Notice all the blank spaces?? guess it doesn't matter. since why woudl anyone in their right mind care?? and the Sector Number who needs that.. lol

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


Tue Jun 05, 2007 6:17 am
Profile ICQ YIM
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Mind Dagger wrote:

Nice work on the code. Some great ideas in there. I tweaked it a little in order to get it running as well as take care of some formatting issues.

Code:
:quikstats
     setArray $quickstats 0
     send "^/q"
     waitfor #179
     while (CURRENTLINE <> ": ENDINTERROG")
               setVar $line CURRENTLINE & #179
               stripText $line ","
               upperCase $line
               :addstat
                  getWord  $line $stat 1 "%%%"
                  getText  $line $quickstats[$stat] $stat&" " #179
                  stripText  $line $stat&" "&$quickstats[$stat]³
                  striptext  $quickstats[$stat] " "
       branch ($stat = "%%%") :addstat
               waitFor " "
     end
return 


Hey MD. your routine didn't work. here's a working version. had to add a line because $stat = "%%%" needed to be cleared for next Stat Line read via CURRENTLINE

Code:
:quiker_stats
    setArray $quickstats 0
     send "^/q"
     waitfor #179
     while (CURRENTLINE <> ": ENDINTERROG")
             setVar $line CURRENTLINE & #179
             stripText $line ","
             upperCase $line
             While ($stat <> "%%%")
             getWord $line $stat 1 "%%%"
             getText $line $quickstats[$stat] $stat&" " #179
             stripText $line $stat&" "&$quickstats[$stat] & #179
             striptext $quickstats[$stat] " "
             end
             setVar $stat ""
             waitFor " "
     end
     return

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


Tue Jun 05, 2007 6:36 am
Profile ICQ YIM
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Here's my submission 15 Lines:
Code:
:Quikstat
setVar $Stat 0
send "^/q"
while (CURRENTLINE <> ": ENDINTERROG")
     waitfor " "
     setVar $Result CURRENTLINE
     ReplaceText $Result #179 " "
     StripText $Result ","
     UpperCase $Result
     setVar $i 1
     While ($i <= 24)
           getWord $Result $Temp $i
           getWord $Result $Stat[$Temp] ($i + 1)
           add $i 2
     end
end
return

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


Tue Jun 05, 2007 6:56 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Only problem w/ processing lines seperately is that sometimes a stat is broken across lines. How are you handling that?

_________________
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


Tue Jun 05, 2007 7:44 am
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Singularity wrote:
Only problem w/ processing lines seperately is that sometimes a stat is broken across lines. How are you handling that?


I have honestly never seen/noticed that happen (esp in the case of "^/Q") ... is that reproducible? if it the stat line can be broken or interrupted, then how can any routine handle that beyond detecting errant-data and Loop back to the start?   Perhaps there should be a new challenge: Who can make the most Bullet-Proof quickstat routine, in the fewest number of lines.. hehe.

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


Tue Jun 05, 2007 8:09 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
I've seen it happen, mostly on the ship number stat. That's why most gather all of the lines together before processing, so any splits like that are fixed. As for the bulletproof thing... any major bugs like that are a problem, IMO. What good is a routine if it might randomly break?

_________________
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


Tue Jun 05, 2007 8:50 pm
Profile ICQ WWW
Gameop
User avatar

Joined: Thu Mar 08, 2001 3:00 am
Posts: 886
Location: USA
Unread post 
so did i miss EP's solution?

_________________
twgs : telnet://twgs.thereverend.org:5023
web : http://www.thereverend.org
games : http://www.thestardock.com/twgssearch/i ... verend.org
helper : http://svn.thereverend.org:8080/revhelper/


Tue Jun 05, 2007 10:57 pm
Profile
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post 
Well guys, I've been very impressed thus far. There have been some really innovative ideas thrown at this problem. I especially liked the RAWPACKET approach, as it can shave a line or two... but as Sing pointed out, it isnt' guaranteed to return the whole quickstat packet.

It has always bugged me that quickstat routines took so many lines. I remember a thread from several years ago that included posts by some of the best scripters in the game at that time (Traitor, CK, SupG, etc.) which basically conceded that a quickstat routine just couldn't be more concise than about 40 lines. One of the reasons for this was the way that the getText function worked in TWX, which has been corrected in v2.04. And so, as you can see by the previous posts, much more concise variations are now possible... thankfully.

Now, I submit to you that I have just completed a working 12-line routine that meets the minimum requirements, but none of the bonus requirements. However, if anyone can prove that it's possible for a stat name and value (other than ship type) to be on different lines, then this solution won't work. I'll post it tomorrow if I can't figure out a way to lose another line

Anyone else successful in the 12 or 13 line range?

+EP+

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


Wed Jun 06, 2007 8:32 pm
Profile WWW
Lieutenant J.G.

Joined: Fri Apr 05, 2002 3:00 am
Posts: 332
Location: USA
Unread post 
LoneStar wrote:

I had to remove the Branch thing because it otherwise wouldn't work --for me at least. Notice all the blank spaces?? guess it doesn't matter. since why woudl anyone in their right mind care?? and the Sector Number who needs that.. lol

You're being rather rude, but anyway, I don't have TWX running so I couldn't even test it.  That's why I asked whether it'd work.  I have no scripting experience, I was just trying to add ideas to the thread.  If the bug is what I think it is (though you didn't say exactly), adding a line to strip spaces from the data should've made the program work and still stay below 15 lines.  A bug that one extra line will fix does not make the entire script worthless as you inferred.  If the cutText function worked the same way getText did, or cutWord existed in the same way as getWord, the capture and delete functions could even be performed simultaneously, but unfortunately (and incongruously) cutText uses length instead of an end location.
I'm not sure why the branch function didn't work; if the documentation is correct (and it sounds like it's not ) branch (condition) :location should be the exact same as if (condition) / goto :location / end, and condense 3 lines into 1.  It should've functioned as a do/while loop, which differs from a while loop in that the first iteration occurs *before* testing the condition, so you won't have to worry about reinitializing the conditional variable if the subroutine is going to be called twice. 
The point was just to throw another idea out there (the delete as you go method) that ANOTHER scripter might be able to take and run with and do far better with than I did.  Rudely telling me my script sucks, on the other hand, was much less productive.
As for sector data, I still don't personally see the point since TWX *automatically* captures the current sector anytime it shows up and puts it in a CURRENTSECTOR global.  At least, that's what it does from what I understood of the documentation.  If it misses the sector in a quickstat display, that's something that seems to me like should be fixed in the TWX code itself.  It could even be argued that global variables for everything on the quickstat list should be added and automatic tracking/parsing of that data built-into the next version of TWX itself, especially since, as Elder says, it's not the easiest functionality to script in a small way.  It'd also make parsing and reading that data faster, and most of that data is of frequent importance (thus the point of a quickstat parsing routine).

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


Wed Jun 06, 2007 9:16 pm
Profile ICQ YIM
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Xentropy wrote:
You're being rather rude, but anyway, I don't have TWX running so I couldn't even test it.  That's why I asked whether it'd work.  I have no scripting experience, I was just trying to add ideas to the thread.  If the bug is what I think it is (though you didn't say exactly), adding a line to strip spaces from the data should've made the program work and still stay below 15 lines.  A bug that one extra line will fix does not make the entire script worthless as you inferred.  If the cutText function worked the same way getText did, or cutWord existed in the same way as getWord, the capture and delete functions could even be performed simultaneously, but unfortunately (and incongruously) cutText uses length instead of an end location.
I'm not sure why the branch function didn't work; if the documentation is correct (and it sounds like it's not ) branch (condition) :location should be the exact same as if (condition) / goto :location / end, and condense 3 lines into 1.  It should've functioned as a do/while loop, which differs from a while loop in that the first iteration occurs *before* testing the condition, so you won't have to worry about reinitializing the conditional variable if the subroutine is going to be called twice. 
The point was just to throw another idea out there (the delete as you go method) that ANOTHER scripter might be able to take and run with and do far better with than I did.  Rudely telling me my script sucks, on the other hand, was much less productive.
As for sector data, I still don't personally see the point since TWX *automatically* captures the current sector anytime it shows up and puts it in a CURRENTSECTOR global.  At least, that's what it does from what I understood of the documentation.  If it misses the sector in a quickstat display, that's something that seems to me like should be fixed in the TWX code itself.  It could even be argued that global variables for everything on the quickstat list should be added and automatic tracking/parsing of that data built-into the next version of TWX itself, especially since, as Elder says, it's not the easiest functionality to script in a small way.  It'd also make parsing and reading that data faster, and most of that data is of frequent importance (thus the point of a quickstat parsing routine).



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 always design a script with the expectation of the output actually being read somewhere later.

Parameters of the Challenge issued require that you put aside you thoughts on CURRENTSECTOR and submit a Sub-Routine that reports all elements of a QuickStat. Please and Thank You.

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


Wed Jun 06, 2007 9:50 pm
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 41 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.