From NEAT Portal Wiki
Jump to: navigation, search


The information contained in this section is all my own personal musings. There are no hard, fast, correct or incorrect ways to write a script, per se. The creators of Y.A.E.B. have gone to painstaking lengths to make the bot totally foolproof. It will save your city whether you want it to or not. They are so adamant about this aspect of the bot that the abandonttown command has been disabled. You cannot lose a city if you try.

Scripts are the exception to the safety rule. Other than the removal of the abandontown command, there are no safety nets. If you disband your army, demolish your defences of squander your resources, they are gone, plain and simple. There is no undo key, nor will <ctrl>-z do you any good.

I volunteered to write this section for 2 reasons: 1: I am ex-aerospace toolmaker in SoCal, which in the 1980's and 90's was the ultimate thing to do in the ultimate place to do it. I was there the day they rolled both the F-117A Stealth fighter and The B1-B bomber out of the hangars. I am not a rocket scientist, but I did design and build all of the tooling used in the manufacture of the retro-rokets of the Atlas-Centaur Launch Vehicle ( a sattelite/heavy cargo platform). (Those are the things that keep it from tipping over at launch, like the infamous Russian rocket did in the video). I am a toolmaker, which is the highest title attainable in the machinist trade. I can and have run virtually every type of manufactiuing tool there is, from 1950's series Cincinnati shaper mills, to state of the art cnc lasers and machine centers to the latest in rapid prototying equipment. I have built machines ranging from 2 axis pattern cutters, to the robot that polishes the inside of the naval I.C.B.M. launch tubes. (Before which time it was done by hand by a tiny little Korean kid who crawled through with a buffer...). I can program the computers or turn the handles. It does not matter to me. If it can be built, I can build it. Then the goverment stepped in and in their stupidly misplaced efforts to protect us from ourselves (not to be confused with disabling the abandontown command) outlawed most of the chemicals and materials used in said industry, without which the industry could not function. So now there is no more Lockheed skunk-works, Boeing, Martin-Marietta, Nothrop, Raytheon, or any other such company in the entire state that wwas 20 years ago home to them all.

So I started building custom Harleys, even had a shop, but the government in its further efforts to destroy what was once the 6th largest economy in the world by itself have forced my shop to close because I cannot afford the over $35,000 in fees, licenses, permits along with the 10% of everything city tax to go along with the 30% off the top business tax. They charged me an $800 compressor inspection fee. The man had no idea what he was doing, given the fact it was a 30 yr old compressor with one bad cylinder, less efficient than a bicycle pump.

The bottom line is I am about as broke as they come, and since I cannot donate cash, I donate time and knowledge. Don't kid yourself, in this whacked out economy there is such a thing as knowing too much to get a job....

The second reason is: I am as egocentic as they come and firmly beleive some of the tricks and tips I am willing to give up are worth far more than a $30 dollar contribution. (Wouldn't you like to know the ones I don't give up...???)

But I am not perfect by any means, nor even close to the best scripter out there. Which is why I appeal to you all, readers of this wiki, for your opinions, critisisms and suggestions. This is a wiki, but I think it is a locked wiki (??). If you cannot message or contact me through the tabs at the top of this page, my name is Schwack, please feel free to p.m. me from the Y.A.E.B. forums. I may miss messages here, but I recieve notification of any messages there. As anyone who has ever asked can attest, I am always willing to help or explain or answer any questions (if I can...) and I am a pretty good Evony player to boot. The one thing I will not tell is how to beat the bot, until we meet on a battlefield and come to realize what your and my favorite dev means by 'A properly configured bot'. Ok, enough b.s.

In this section we will look at some advanced techniques for saving memory, creating reusable blocks and methods of keeping things under control.

The Rules

Rule #1: Test your script!
This is particularily important for attack scripts and any script that destroys a troop, building or wall defense.
Ideally you would test any such script in an empty city. It is ok to produce errors when you expect them.
Set quantities to minimum numbers until you are sure the script functions properly.
Before you run your market script to sell 9,999,999 food at a time, run it through selling 100 just to test the logic.
Rule #2: Keep your scripts as compact and simple as possible.
This includes using gosub routines and replaceable variables.
Rule #3: Be sure you have enough troops, resources, heroes, and most importantly, time.
There is nothing worse than getting to wave #8 and encountering an "Illegal camp time ignored" error.
Before running an attack script against your enemy, run it against an npc 1 mile beyond your enemy.
This will be further discussed in the attack section.

Y.A.E.B. contains space for 5 scripts per city. You should take advantage of these spaces to store scripts that you use regularly.

Kiss your script

Kiss stands for 'Keep it simple, stupid'. The best way to do this is with sub-routines. Any time your script does the same thing more than once, you should use a sub-routine. Bear in mind, however, that there is absolutely no advantage to having a sub-routine who's only function is to send you somewhere else.

Use repeat and loop whenever you want to run the same command or chunk of commands more than once. Replaceable variables are by far the most economical way to keep your script compact and make it reuseable.

The Simple Attack script is a good example. Simply changing the set xy xxx,yyy and set army xxxx lines will allow you to send any army to any city. The Schwack Attack, found immediately following the previous example is a far more complex example . I keep a copy in one of the script spaces of every city.

The Schwack Attack also demonstrates a simple way of selecting an option from multiple choices. Only the first goto command encountered is able to run, so you simply cut the and paste the attack you want to perform into the first position and run the script. It is best to set the 'always run script from line #1' option in the misc. page of the options. The script was written before this option was availible, and I have since eliminated the 'goto top' line from the end of the script.

Replacable Variables Example

Scripts take up memory. If you have 3 accounts with 9 cities each, with all of them running a 150 line script, you will find yourself hard-pressed for memory real quick.

BigBill wrote an excellen script to convert a lvl10 npc. It ran 172 lines. Here is the same concept (ty, BigBill, the concept is the hard part) reduced to 1/5 the size.

// city can be iron or wood
set city iron

// barx = # of cottages to convert
set barx 6

// lvl10_barx = how many to turn lvl10
set lvl10_barx 9

1: goto %city%

2: label build_bldg
3: create %new_bldg%
4: upgrade %new_bldg%
5: repeat 8
6: gosubreturn

7: label demo_bldg
8: demo %old_bldg% level10
9: demo %old_bldg%
10: repeat 9
11: gosubreturn

12: label doit
13: gosub demo_bldg
14: gosub build_bldg
15: gosubreturn

16: label iron
set new_bldg i
set old_bldg s
17: goto fields

18: label wood
set new_bldg s
set old_bldg i

19: label fields
20: gosub doit
set old_bldg q
21: gosub doit
set old_bldg f
22: gosub doit
23: repeat 37

set new_bldg b
set old_bldg fo
24: gosub doit
set old_bldg ws
25: gosub doit
set old_bldg st
26: gosub doit
27: ifgoto ( %barx% == 0 ) upbarx
set old_bldg c
28: gosub doit
29: repeat %barx%

30: label upbarx
31: ifgoto ( %lvl10_barx% == 0 ) end
32: upgrade b level10
33: repeat %lvl10_barx%

There are certain caseswhich do not support changing variables 'on-the-fly'. The most notable that I have found so far are the city manager arrays. This is demonsrtated in the following example:

Array Demo

 1: goto start
 2: label output
 3: print x %n%
 4: print x ( m_city.cityManager.heroes[%n%].name )
 5: gosubreturn
 6: label start
 set n 0
 7: gosub output
 set n 1
 8: gosub output
 set n 2
 9: gosub output

Gives us:

19:15:49 Running line 1
19:15:49 Going to line 6
19:15:51 Running line 7
19:15:51 Going to line 2
19:15:53 Running line 3
19:15:53 %n% 
19:15:55 Running line 4
19:15:55 ( ace ) 
(Here '%n% is undefined, therefore it defaults to 0, hero[0] is ace)
19:15:57 Running line 5
19:15:57 Returning to line 7
19:15:59 Running line 8
19:15:59 Going to line 2
19:16:01 Running line 3
19:16:01 %n% 
19:16:03 Running line 4
19:16:03 ( ace ) 
19:16:05 Running line 5
19:16:05 Returning to line 8
19:16:07 Running line 9
19:16:07 Going to line 2
19:16:09 Running line 3
19:16:09 %n% 
19:16:11 Running line 4
19:16:11 ( ace ) 
19:16:13 Running line 5
19:16:13 Returning to line 9
19:16:14 Finished script

Running the script again results in:

19:16:19 Running line 1
19:16:19 Going to line 6
19:16:21 Running line 7
19:16:21 Going to line 2
19:16:23 Running line 3
19:16:23 2 
(Here it recalls the last value set in the script...Hero[2] is k)
19:16:25 Running line 4
19:16:25 ( k ) 
19:16:27 Running line 5
19:16:27 Returning to line 7
19:16:29 Running line 8
19:16:29 Going to line 2
19:16:31 Running line 3
19:16:31 2 
19:16:33 Running line 4
19:16:33 ( k ) 
19:16:35 Running line 5
19:16:35 Returning to line 8
19:16:37 Running line 9
19:16:37 Going to line 2
19:16:39 Running line 3
19:16:39 2 
19:16:41 Running line 4
19:16:41 ( k ) 
19:16:43 Running line 5
19:16:43 Returning to line 9
19:16:44 Finished script

Ok, lets try changing the last set to..

8: gosub output
set n 1
9: gosub output

This results in:

19:28:55 Running line 1
19:28:55 Going to line 6
19:28:57 Running line 7
19:28:57 Going to line 2
19:28:59 Running line 3
19:28:59 2 
19:29:01 Running line 4
19:29:01 ( k ) 
19:29:03 Running line 5
19:29:03 Returning to line 7
19:29:05 Running line 8
19:29:05 Going to line 2
19:29:06 Script Stopped

It still retains the previous value, and will 'ad infinitum' except for:
19:29:06 Script Stopped
This changes things. Watch:

19:32:20 Running line 1
19:32:20 Going to line 6
19:32:22 Running line 7
19:32:22 Going to line 2
19:32:24 Running line 3
19:32:24 1 
19:32:26 Running line 4
19:32:26 ( a ) 
19:32:28 Running line 5
19:32:28 Returning to line 7
19:32:30 Running line 8
19:32:30 Going to line 2

Ani you can do it over and over and over. The first time you run it, the variable will have a value of 0 and it will retain that value until the script is done. The next and every subsequent time you run it, the script will retain the last value it encountered the first time it ran.. Changing the value in the script has no effect. It will be whatever it was when the script finished running the very first time, even if you run it 100 times.. Unless, the script is stopped. Then it will retain the last value set by the script in the condition it was last run in, even if the script never gets to the line in which the variable was set..

So, to change the value, you have to change the script, start and stop the script, then run it again for the new value to be effective....

So why am I telling you all of this? Because this is the advanced class....

And to offer a once in a lifetime chance for your name to go down in history, for the first individual that can devise a working solution to this somewhat confounding conundrum....