02-11-2021, 06:39 PM
(This post was last modified: 02-11-2021, 06:45 PM by Splints. Edited 1 time in total.)
(02-10-2021, 07:08 PM)aft2001 Wrote: That's actually super genius. How difficult was it to make? I'd love to have it or one I make for myself, though I'll have to hand copy it in-game given the fact that I play AI a ton.
Thanks! The hard part was learning how to get if/else statements working and I owe a lot to the help I got from people on discord. I'm happy to share the script, but if you would rather discover things on your own I'll just put some of the key DWAINE tactics here. If you want the full script just let me know, here or discord.
1)If statements are formatted as follows.
if <condition> ^ True statement 1 ^ True statement 2 ^ etc ^ else ^ false statement 1 ^ false statement 2 ^ etc
Example for testing if two variables are equal:
if $a $b eq ^ echo equal ^ else ^ echo not equal
Since if statements include ^ in them, they cannot be used in a script. You can get around this by writing it on paper and scanning it in. However, since you only need to run it once and already need to hand copy it line by line as AI, this shouldn't be a problem.
2) The results of a teleman scan can be saved to a file with ^
For example, to save the result to a file called scanres you could write
teleman scan ^ scanres
3) Grep can be very useful for doing string/substring stuff. With the -o option it returns only the matching part so if you have file that you want to see if it contains the substring TEST (case sensitive), you can use
grep -o TEST filename
This will either return null or TEST
Combine this with 'if' to check if a file contains a substring
if ATEST A$(grep -o TEST filename) eq
If filename contains TEST, ATEST = ATEST and the result is true. If it does not ATEST does not equal A and the result if false. The A prevents an underflow error as grep returns nothing if false. Any character or string can be used instead of A.
4) If you can find the max corner of the map (300,300 on a GPS) you can find all of the offset terms. The add term is a whole number from 0 and 100 and the slope term can only be 1, 0.5, 0.25. Multiplication happens after the add.
5) While loops don't work. They are only partially implemented so 'while' does not return a syntax error, but it does not loop. You can instead just write out loops in sequence in your script. Mine is 84 lines long, but most of it is the 7 iterations of the binary search.
6) DWAINE is super finicky in a lot of ways. I've found unsetting a variable sometimes unsets them all. Scope is weird when it comes to scripts with variables sometimes passing in or out and sometimes not. I'm not sure what the underlying rule is, but I generally prefer to keep everything in one script to prevent issues. I tried using subroutines but it was just too much of a pain.
(Also, happy birthday!)