Author |
Message |
Assaulter
Warrant Officer
Joined: Thu May 09, 2013 2:21 pm Posts: 73
|
 Re: My Very First Attempt to Write a script
Worked great. Thanks!
_________________ -Zoom
Zoom's Team Speak3 Server @ ts3server://vs26.tserverhq.com:7214 TradeWars2002: The Basics @ http://playtwars.altervista.org
|
Wed Mar 26, 2014 10:07 pm |
|
 |
Assaulter
Warrant Officer
Joined: Thu May 09, 2013 2:21 pm Posts: 73
|
 Re: My Very First Attempt to Write a script
I have hit another road block. I have tried a few different variations to my current code with little success. I finally thought I had it but the script terminates right after attempting to collect the information. I'm sure there are lots of things wrong with it but any tips would be appreciated. Code: getWordPos CURRENTLINE $pos "Command [TL=" if ($pos <> 1) echo "**" &ANSI_14& " Must Start at Command Prompt. Exiting..." halt end
:HowMany getInput $howmany "***" &ANSI_11& "How many planets would you like to Neg?" isNumber $isNumber1 $howmany if ($isNumber1 = FALSE) echo "**" &ANSI_14& "Please enter a number." goto :HowMany elseif ($howmany >= "8") echo "**" &ANSI_14& "This script only supports up to 7 planets" goto :HowMany elseif ($howmany > SECTOR.PLANETCOUNT[CURRENTSECTOR]) echo "**" &ANSI_14& "There aren't that many planets in the sector." goto :HowMany else setvar $count $howmany end
setArray $planets $count setArray $used 0 setArray $eqInput 0 setArray $orgInput 0 setArray $gasInput 0 setVar $i 1 setVar $eq 1 setvar $org 1 setvar $gas 1 while ($i <= $count) and ($eq <= $count) and ($org <= $count) and ($gas <= $count) getInput $input "**" &ANSI_11& "What is the number for Planet " & $i & "?" isNumber $isNumber2 $input if ($isNumber2 = FALSE) echo "**" &ANSI_14& "Um, try putting in a number." elseif ($used[$input] = TRUE) echo "**" &ANSI_14& "That planet number isn't unique. Try again." else setVar $planets[$i] $input setVar $used[$input] TRUE end getinput $eqSell "**" &ANSI_11& "How much EQU do you want to sell? --- Enter number of holds, the number 1 for max holds, or the number 2 for none " isNumber $isNumber3 $eqSell if ($isNumber3 = FALSE) echo "**" &ANSI_14& "That wasn't a number!" elseif ($isnumber3 > "65530") echo "**" &ANSI_14& "Ehhhh... No port can afford that much product. Try a smaller number." else setvar $planets[$i][$eq] $eqSell setvar $eqInput[$eqSell] true end getinput $orgSell "**" &ANSI_11& "How much ORG do you want to sell? --- Enter number of holds, the number 1 for max holds, or the number 2 for none " isNumber $isNumber4 $orgSell if ($isNumber4 = FALSE) echo "**" &ANSI_14& "That wasn't a number!" elseif ($isnumber4 > "65530") echo "**" &ANSI_14& "Ehhhh... No port can afford that much product. Try a smaller number." else setvar $planets[$i][$org] $orgSell setvar $orgInput[$orgSell] true end getinput $gasSell "**" &ANSI_11& "How much FUEL do you want to sell? --- Enter number of holds, the number 1 for max holds, or the number 2 for none " isNumber $isNumber5 $gasSell if ($isNumber5 = FALSE) echo "**" &ANSI_14& "That wasn't a number!" elseif ($isnumber5 > "65530") echo "**" &ANSI_14& "Ehhhh... No port can afford that much product. Try a smaller number." else setvar $planets[$i][$gas] $gasSell setvar $gasInput[$gasSell] true end add $i 1 add $eq 1 add $gas 1 add $org 1 end
setVar $i 1 setVar $eq 1 setVar $org 1 setVar $eq 1 while ($i <= $count) and ($eq <= $count) and ($org <= $count) and ($gas <= $count)
if ($planets[$i][$eq] = 1) SetVar $_CK_PNEGO_EQUIPTOSELL "max" elseif ($planets[$i][$eq] = 2) setvar $_CK_PNEGO_EQUIPTOSELL "-1" else setvar $_CK_PNEGO_EQUIPTOSELL $planets[$i][$eq] end SaveVar $_CK_PNEGO_EQUIPTOSELL
if ($planets[$i][$org] = 1) SetVar $_CK_PNEGO_ORGTOSELL "max" elseif ($planets[$i][$org] = 2) setvar $_CK_PNEGO_ORGTOSELL "-1" else setvar $_CK_PNEGO_ORGTOSELL $planets[$i][$org] end SaveVar $_CK_PNEGO_ORGTOSELL
if ($planets[$i][$gas] = 1) SetVar $_CK_PNEGO_FUELTOSELL "max" elseif ($planets[$i][$gas] = 2) setvar $_CK_PNEGO_FUELTOSELL "-1" else setvar $_CK_PNEGO_FUELTOSELL $planets[$i][$gas] end SaveVar $_CK_PNEGO_FUELTOSELL
send "l" $planets[$i] "*" waiton "Fuel Ore" waiton "elp) [D]" load "scripts\_ck_planet_nego.cts" waiton " --- Done with port" send "q" add $i 1 add $eq 1 add $org 1 add $gas 1 end SetVar $_CK_PNEGO_FUELTOSELL "DELETED" SetVar $_CK_PNEGO_ORGTOSELL "DELETED" SetVar $_CK_PNEGO_EQUIPTOSELL "DELETED" SaveVar $_CK_PNEGO_FUELTOSELL SaveVar $_CK_PNEGO_ORGTOSELL SaveVar $_CK_PNEGO_EQUIPTOSELL
halt
Thanks
_________________ -Zoom
Zoom's Team Speak3 Server @ ts3server://vs26.tserverhq.com:7214 TradeWars2002: The Basics @ http://playtwars.altervista.org
|
Fri Mar 28, 2014 2:05 am |
|
 |
OldDragon
Sergeant
Joined: Mon Jan 06, 2014 11:01 pm Posts: 8
|
 Re: My Very First Attempt to Write a script
I can't speak much about scripting as I don't really know much about TWX beyond what I've looked at to fixed the occasional script. I did go through and add some general programming comments. Code: getWordPos CURRENTLINE $pos "Command [TL=" if ($pos <> 1) echo "**" &ANSI_14& " Must Start at Command Prompt. Exiting..." halt end
:HowMany getInput $howmany "***" &ANSI_11& "How many planets would you like to Neg?" isNumber $isNumber1 $howmany if ($isNumber1 = FALSE) echo "**" &ANSI_14& "Please enter a number." goto :HowMany elseif ($howmany >= "8") # would recommend checking a range here (1 to 7) as they could put in a negative number echo "**" &ANSI_14& "This script only supports up to 7 planets" goto :HowMany elseif ($howmany > SECTOR.PLANETCOUNT[CURRENTSECTOR]) echo "**" &ANSI_14& "There aren't that many planets in the sector." goto :HowMany else setvar $count $howmany end
setArray $planets $count setArray $used 0 setArray $eqInput 0 setArray $orgInput 0 setArray $gasInput 0 setVar $i 1 setVar $eq 1 # seems like these are supposed to be the indexes of the different types, probably want 1, 2 and 3 setvar $org 1 setvar $gas 1 while ($i <= $count) and ($eq <= $count) and ($org <= $count) and ($gas <= $count) # I imagine you just want to test that $i is less than $count here. getInput $input "**" &ANSI_11& "What is the number for Planet " & $i & "?" isNumber $isNumber2 $input if ($isNumber2 = FALSE) echo "**" &ANSI_14& "Um, try putting in a number." # missing a goto to get a new number elseif ($used[$input] = TRUE) echo "**" &ANSI_14& "That planet number isn't unique. Try again." # missing a goto to get a new number else setVar $planets[$i] $input setVar $used[$input] TRUE end getinput $eqSell "**" &ANSI_11& "How much EQU do you want to sell? --- Enter number of holds, the number 1 for max holds, or the number 2 for none " isNumber $isNumber3 $eqSell if ($isNumber3 = FALSE) echo "**" &ANSI_14& "That wasn't a number!" # missing a goto to get a new number elseif ($isnumber3 > "65530") # should probably be a range check 1 to 65530 echo "**" &ANSI_14& "Ehhhh... No port can afford that much product. Try a smaller number." # missing a goto to get a new number else setvar $planets[$i][$eq] $eqSell setvar $eqInput[$eqSell] true end getinput $orgSell "**" &ANSI_11& "How much ORG do you want to sell? --- Enter number of holds, the number 1 for max holds, or the number 2 for none " isNumber $isNumber4 $orgSell if ($isNumber4 = FALSE) echo "**" &ANSI_14& "That wasn't a number!" # missing a goto to get a new number elseif ($isnumber4 > "65530") # should probably be a range check 1 to 65530 echo "**" &ANSI_14& "Ehhhh... No port can afford that much product. Try a smaller number." # missing a goto to get a new number else setvar $planets[$i][$org] $orgSell setvar $orgInput[$orgSell] true end getinput $gasSell "**" &ANSI_11& "How much FUEL do you want to sell? --- Enter number of holds, the number 1 for max holds, or the number 2 for none " isNumber $isNumber5 $gasSell if ($isNumber5 = FALSE) echo "**" &ANSI_14& "That wasn't a number!" # missing a goto to get a new number elseif ($isnumber5 > "65530") echo "**" &ANSI_14& "Ehhhh... No port can afford that much product. Try a smaller number." # missing a goto to get a new number else setvar $planets[$i][$gas] $gasSell setvar $gasInput[$gasSell] true end
add $i 1 add $eq 1 # assuming these are the indexes for the types, they shouldn't be incremented add $gas 1 add $org 1 end
setVar $i 1 setVar $eq 1 # again, assuming these were supposed to be specific indexes, they wouldn't need to be reset here. setVar $org 1 setVar $eq 1 while ($i <= $count) and ($eq <= $count) and ($org <= $count) and ($gas <= $count) # again, these are always going to be the same as they are setup currently, so only one needs to be checked. if ($planets[$i][$eq] = 1) SetVar $_CK_PNEGO_EQUIPTOSELL "max" elseif ($planets[$i][$eq] = 2) setvar $_CK_PNEGO_EQUIPTOSELL "-1" else setvar $_CK_PNEGO_EQUIPTOSELL $planets[$i][$eq] end SaveVar $_CK_PNEGO_EQUIPTOSELL
if ($planets[$i][$org] = 1) SetVar $_CK_PNEGO_ORGTOSELL "max" elseif ($planets[$i][$org] = 2) setvar $_CK_PNEGO_ORGTOSELL "-1" else setvar $_CK_PNEGO_ORGTOSELL $planets[$i][$org] end SaveVar $_CK_PNEGO_ORGTOSELL
if ($planets[$i][$gas] = 1) SetVar $_CK_PNEGO_FUELTOSELL "max" elseif ($planets[$i][$gas] = 2) setvar $_CK_PNEGO_FUELTOSELL "-1" else setvar $_CK_PNEGO_FUELTOSELL $planets[$i][$gas] end SaveVar $_CK_PNEGO_FUELTOSELL
send "l" $planets[$i] "*" waiton "Fuel Ore" waiton "elp) [D]" load "scripts\_ck_planet_nego.cts" waiton " --- Done with port" send "q"
add $i 1 add $eq 1 # assuming these are the indexes for the types, they shouldn't be incremented add $org 1 add $gas 1 end
SetVar $_CK_PNEGO_FUELTOSELL "DELETED" SetVar $_CK_PNEGO_ORGTOSELL "DELETED" SetVar $_CK_PNEGO_EQUIPTOSELL "DELETED" SaveVar $_CK_PNEGO_FUELTOSELL SaveVar $_CK_PNEGO_ORGTOSELL SaveVar $_CK_PNEGO_EQUIPTOSELL
halt # this should be unnecessary
|
Fri Mar 28, 2014 8:38 pm |
|
 |
ElderProphet
Commander
Joined: Tue Oct 07, 2003 2:00 am Posts: 1124 Location: Augusta, GA
|
 Re: My Very First Attempt to Write a script
It's bad form to post your script and ask someone to fix it for you.
Tips for when a script terminates prematurely... Use lots of echos to see where the script is at and what it's doing Check your while/end pairs Check your if/end pairs Move code around to simplify that section of the script
Hope that helps.
_________________ Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.
|
Fri Mar 28, 2014 10:52 pm |
|
 |
Assaulter
Warrant Officer
Joined: Thu May 09, 2013 2:21 pm Posts: 73
|
 Re: My Very First Attempt to Write a script
Thank you for your tips OldDragon. I appreciate your help a great deal.
ElderProphet. Thanks for your help thus far. You have helped me quite a lot. I guess that is why I didn't realize this forum was above someone trying to learn TWX. I wasn't asking for anyone to fix it. Just tips on something I may be doing wrong. However, I have noted this and will no longer post here.
Thanks
_________________ -Zoom
Zoom's Team Speak3 Server @ ts3server://vs26.tserverhq.com:7214 TradeWars2002: The Basics @ http://playtwars.altervista.org
|
Mon Mar 31, 2014 1:15 pm |
|
 |
Cruncher
Ambassador
Joined: Fri Feb 23, 2001 3:00 am Posts: 4011 Location: USA
|
 Re: My Very First Attempt to Write a script
Assaulter wrote: ... I wasn't asking for anyone to fix it. Just tips on something I may be doing wrong... I feel your pain, I'm currently in college to learn programming. Many times I'm stuck simply asking the "right question". It's hard to ask if you aren't clear on what exactly you're looking for. I think if you try to be a little more specific, where exactly is the code hanging up at, what are you trying to accomplish? Some screen shots of errors is sometimes helpful. FYI - I know next to nothing about TWX. I'm currently learning HTML5, CSS3, Responsive Design, C#, JavaScript, ASP.Net, SQL Server. I've been banned from a developer forum for not asking "the right question". 
_________________
BOTE 1998 Champs: Team Fament HHT 2015 Champs: Cloud09 Big Game 2016 Champs: Draft team HHT 2018 Champs: Rock Stars Big Game 2019 Champs: Draft Team
Classic Style Games Here: telnet://crunchers-twgs.com:2002 Web page from 1990's: https://web.archive.org/web/20170103155645/http://tradewars.fament.com/Cruncher/tradewar.htm Blog with current server info: http://cruncherstw.blogspot.com Discord: https://discord.gg/4dja5Z8 E-mail: Cruncherstw@gmail.com FaceBook: http://www.facebook.com/CrunchersTW
|
Tue Apr 01, 2014 8:24 am |
|
 |
LoneStar
Commander
Joined: Fri Jun 09, 2006 2:00 am Posts: 1393 Location: Canada
|
 Re: My Very First Attempt to Write a script
Few things I always do when debugging a script: Make sure Variables are unique and not reused in multiple routnes; Narrow down the routine that's hanging or crashing, copy paste it to another txt/ts file and try to run it from there; Start to whittle down the code that 'works' until your left with the code that's broke; Make sure no other scripts are running simultaneously; Step through the code and check variables as you proceed. I use to insert: Code: Waiton #179 & "Turns" …at strategic points to pause execution so that I could view variables and make sure they're what I expect. To proceed after the waiton, I'd simply press / If all else fails, find another script source that achieves the same task and study it, then if necessary, walk away for a day and start over from scratch. That's the LONESTAR approved method of debugging 
_________________ ---------------------------- -= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time. -= There are 10 types of people in the world: Those that understand Binary and those who do not -= If Oil is made from Dinosaurs, and Plastic is made from Oil... are plastic Dinosaurs made from real Dinosaurs? -= I like to keep my friends and my enemies rich, and wait to see which is which - Tony Stark (R.I.P.)
|
Tue Apr 01, 2014 8:54 am |
|
 |
Assaulter
Warrant Officer
Joined: Thu May 09, 2013 2:21 pm Posts: 73
|
 Re: My Very First Attempt to Write a script
Cruncher. Yes it is hard to ask the right question. Im not sure if the code I have put together is supposed to work or not so I really don't know which part to ask about. The only thing I can do at this point is to put some stuff together that seems logical to me and just use trial and error after that. Lonestar. Thanks for the debugging tips. I will definitely use "the LONESTAR approved method of debugging" in the future. After a couple of days of running things through my head and trying to figure out what I could do differently I decided to fire up my local server and give it another test. It took off and did exactly what it was supposed to do.  What went wrong before? I'm not sure. I am glad I posted about it nonetheless. I was able to get some useful programming and debugging tips. Not to mention, this information is now on file for anyone who may be going down a similar path in the future. Thanks again for your input EDIT: After further testing it wasn't working correctly. It was selling whatever you set the fueltosell variable to of each product. I then reread OldDragon's post and followed his advice and it really does work after extensive testing. Thank you OldDragon.
_________________ -Zoom
Zoom's Team Speak3 Server @ ts3server://vs26.tserverhq.com:7214 TradeWars2002: The Basics @ http://playtwars.altervista.org
|
Tue Apr 01, 2014 11:58 am |
|
 |
Cruncher
Ambassador
Joined: Fri Feb 23, 2001 3:00 am Posts: 4011 Location: USA
|
 Re: My Very First Attempt to Write a script
Good Job! Keep at it!
_________________
BOTE 1998 Champs: Team Fament HHT 2015 Champs: Cloud09 Big Game 2016 Champs: Draft team HHT 2018 Champs: Rock Stars Big Game 2019 Champs: Draft Team
Classic Style Games Here: telnet://crunchers-twgs.com:2002 Web page from 1990's: https://web.archive.org/web/20170103155645/http://tradewars.fament.com/Cruncher/tradewar.htm Blog with current server info: http://cruncherstw.blogspot.com Discord: https://discord.gg/4dja5Z8 E-mail: Cruncherstw@gmail.com FaceBook: http://www.facebook.com/CrunchersTW
|
Tue Apr 01, 2014 7:10 pm |
|
 |
Grey Gamer
Chief Warrant Officer
Joined: Sun Mar 06, 2011 12:22 am Posts: 183
|
 Re: My Very First Attempt to Write a script
ElderProphet wrote: It's bad form to post your script and ask someone to fix it for you. Since I get an error when I try to use Zbot's planetary trader I am trying to start my own. I was going through everything and adding echoes to see where it was going and where it wasn't. I was looking at my code when something happened in-game. I thought that it was an inactivity warning and SWATH sent whatever character it does to keep me in the game. My script finally proceeded--once it received the inactivity warning. I just received another, so I guess that I had better not wait around.
_________________ Photons away!
|
Sun Jun 19, 2022 4:55 pm |
|
 |
|