| www.ClassicTW.com https://mail.black-squirrel.com/ |
|
| twx While https://mail.black-squirrel.com/viewtopic.php?f=15&t=13036 |
Page 1 of 1 |
| Author: | PHX [ Fri Jun 11, 2004 3:24 am ] |
| Post subject: | |
can you use the "and" option with the wile command the same way you would with an "if" command. |
|
| Author: | PHX [ Fri Jun 11, 2004 3:58 am ] |
| Post subject: | |
My tests are telling me no...would be nice to be able to do. setvar $total ($orebust / $hlds) setvar $trips 0 while ($trips <= $total) and ($oreneeds > $hlds) send "t n t 1* q l " $fill "* t n l 1* q l " $bust "* " add $trips 1 subtract $oreneeds $hlds end |
|
| Author: | Cherokee-TLTT [ Fri Jun 11, 2004 11:03 am ] |
| Post subject: | |
I don't know if you can or not, but you might try surrounding the clause with parenthesis, like this... while (($trips <= $total) and ($oreneeds > $hlds)) If you can't get it to work then you'll need to loop without the while, like this... setvar $total ($orebust / $hlds) setvar $trips 0 :loop if (($trips <= $total) and ($oreneeds > $hlds)) send "t n t 1* q l " $fill "* t n l 1* q l " $bust "* " add $trips 1 subtract $oreneeds $hlds goto :loop end |
|
| Author: | ElderProphet [ Fri Jun 11, 2004 12:31 pm ] |
| Post subject: | |
The while command (and almost every other TWX command) handles conditional statements with no problem. I agree with CK 100% about the brackets. I posted what I thought the problem was in response to your question at the TWX forum: http://www.twxproxy.com/support.php?show=654&start=1 In short, it works perfectly as stated, but I think you want the conditional statement to be OR. while (($trips <= $total) or ($oreneeds > $hlds)) Try it and let us know. +EP+ |
|
| Author: | PHX [ Fri Jun 11, 2004 5:29 pm ] |
| Post subject: | |
quote:Originally posted by Cherokee-TLTT I don't know if you can or not, but you might try surrounding the clause with parenthesis, like this... while (($trips <= $total) and ($oreneeds > $hlds)) If you can't get it to work then you'll need to loop without the while, like this... setvar $total ($orebust / $hlds) setvar $trips 0 :loop if (($trips <= $total) and ($oreneeds > $hlds)) send "t n t 1* q l " $fill "* t n l 1* q l " $bust "* " add $trips 1 subtract $oreneeds $hlds goto :loop end I don't know but assumed there would be a significant speed loss if I used the IF instead of WHILE. And in all things TradeWars, speed is key. Im not going to try this method at all unless someone tells me that it will in fact work just as fast as WHILE. I have made scripts with IF commands that had multiple var's before and never put brackets around the whole lot like that and they work just fine. Can you guys explain why this is prefered? |
|
| Author: | PHX [ Fri Jun 11, 2004 5:38 pm ] |
| Post subject: | |
quote:Originally posted by ElderProphet The while command (and almost every other TWX command) handles conditional statements with no problem. I agree with CK 100% about the brackets. I posted what I thought the problem was in response to your question at the TWX forum: http://www.twxproxy.com/support.php?show=654&start=1 In short, it works perfectly as stated, but I think you want the conditional statement to be OR. while (($trips <= $total) or ($oreneeds > $hlds)) Try it and let us know. +EP+ If I used OR, it seems like that after the bust planet has well run out of ore, the fill planet may still have lots of room on it and the OR statement would keep rerunning the macro because of ($oreneeds > $hlds). Ill try the AND first and if it gives me troubles ill give OR a shot. Thanks to both for the help. Someday when I become the Legendary Super Scripter, and threaten to wipe out the entire South Galaxy, you and everyone else who helped me out will get props. Then I gotta figure out how to kick Kakaloto's (Goku's) Butt. |
|
| Author: | Cherokee-TLTT [ Fri Jun 11, 2004 5:45 pm ] |
| Post subject: | |
The while loop has to do an IF internally anyways. There should be 0 speed difference. |
|
| Author: | ElderProphet [ Fri Jun 11, 2004 7:33 pm ] |
| Post subject: | |
With a single And/Or condition, the brackets are inconsequential. But it is good practice for when you get into multiple conditional statements. Like mathematical functions, the conditional components are processed from the innermost to outermost brackets. The first example below will only evaluate as true if $a or $b are > 3, and $a is > $b. The second example is completely different. It will only evaluate as true if $a is > $b & 3, or if $b > 3. 1. if (($a > $b) and (($a > 3) or ($b > 3))) 2. if ((($a > $b) and ($a > 3)) or ($b > 3)) You can see that these two examples will not evaluate the same all of the time, like in this truth table: Example #: |1|2| [a=0][b=4] |0|1| [a=5][b=0] |1|0| Heh, you asked. +EP+ |
|
| Author: | PHX [ Sat Jun 12, 2004 3:14 am ] |
| Post subject: | |
Darn. |
|
| Author: | ElderProphet [ Sat Jun 12, 2004 4:26 am ] |
| Post subject: | |
Heh, too much? That'll teach you to question us!! <grin> +EP+ |
|
| Page 1 of 1 | All times are UTC - 5 hours |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|