• My Pages
  • Comments
  • Add Link
  • Subscribe
  • Subscribe User
  • Edit (GUI)
  • Edit (Text)
  • Rename Page
  • Copy Page
  • Load Page
  • Save Page
  • Delete Page
  • Attachments
  • Check Spelling
  • Diffs
  • Info
  • Revert to this revision
  • XML
  • Render as Docbook
  • Print View
  • Raw Text
  • Delete Cache
  • Like Pages
  • Local Site Map
  • Remove Spam
  • Package Pages
  • Sync Pages
    • Diff for "If"
    Differences between revisions 1 and 2
    Revision 1 as of 2012-12-04 21:52:49
    Size: 1616
    Editor: Inanna
    Comment:
    Revision 2 as of 2012-12-04 21:53:01
    Size: 1617
    Editor: Inanna
    Comment:
    Deletions are marked like this. Additions are marked like this.
    Line 2: Line 2:
    ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">if (city.troop.archer < 20k) train a:5k BigDude || ||<#F2F2F2 style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">Example: ||<style="border-style:solid;border-color:rgb(170, 170, 170);padding:0.2em;">if (city.troop.archer < 20k) train a:5k !BigDude ||

    Usage:

    if (this condition is met) do this stuff

    Example:

    if (city.troop.archer < 20k) train a:5k BigDude

    Just like the IfGoto and IfGosub commands, this will check if some condition is met first. Unlike those scripts however, it doesn't need to jump to a label elsewhere to perform an action based on the condition, it can instead perform it right there on the line. This allows you much more power and flexibility to create your scripts.

    In the 1st example above, if the city has less than 20k archers, then it will train 5k archers with the hero BigDude and carry on to the next line (if one exists).

    If can also use goto/gosub jumps to labels in it, for example: .

    if (city.troop.archer < 20k) gosub trainarchers
    sleep 300
    loop
    
    label trainarchers
    train a:5k BigDude
    gosubreturn

    While we do not yet support && and || operations in Ifs, you can check for more than one condition to be met with nested Ifs, for example:

    .

    if (a == 1) if (b == 1) echo "Both a and b are equal to 1"


    ScriptControlStructures

    If (last edited 2012-12-04 22:02:34 by Inanna)