Results 1 to 7 of 7

Thread: Lich script help

  1. Default Lich script help

    Would this be a logical routine?

    Code:
    def attack_routine
      fput 'stand' if not standing?
      if ((checkmana > 2), (checkhealth > 40), (checkspirit > 5), (checknpcs "critter1")) 
        fput 'target critter1'
        fput 'stance off'
        fput 'incant 702'
      elsif ((checkmana > 2), (checkhealth > 40), (checkspirit > 5), (checknpcs "critter2"))
        fput 'target critter2'
        fput 'stance off'
        fput 'incant 702'
      else
        goto "gohome"
      end
    end

  2. #2
    Join Date
    Jul 2003
    Location
    St. Louis, MO
    Posts
    4,271

    Default

    That's not how you use the comma operator. You want to do:
    Code:
    if ( ( checkmana > 2 ) and ( checkhealth > 40 ) and ( checkspirit > 5 ) )
    Also, instead of testing all that twice, you can test for the health/spirit conditions, then check to the npcs (or the other way around, which is probably what I'd do).
    Quote Originally Posted by Patrick McGoohan
    I am not a number, I am a free man!

  3. #3
    Join Date
    Jul 2003
    Location
    St. Louis, MO
    Posts
    4,271

    Default

    Also, DON'T USE GOTO, unless you really, really, really have to and even then, you can probably get around it.
    Quote Originally Posted by Patrick McGoohan
    I am not a number, I am a free man!

  4. Default

    BigWorm:
    That's not how you use the comma operator. You want to do:

    Code:
    if ( ( checkmana > 2 ) and ( checkhealth > 40 ) and ( checkspirit > 5 ) )
    Wow, thanks. Still learning. That helps alot.

    BigWorm:
    Also, instead of testing all that twice, you can test for the health/spirit conditions, then check to the npcs (or the other way around, which is probably what I'd do)
    So this then?

    Code:
    def attack_routine
      fput 'stand' if not standing?
      while ((checkmana > 2) and (checkhealth > 40) and (checkspirit > 5))
       if checknpcs("critter1") 
        fput 'target critter1'
        fput 'stance off'
        fput 'incant 702'
       elsif checknpcs("critter2")
        fput 'target critter2'
        fput 'stance off'
        fput 'incant 702'
       else
        goto "gohome"
      end
    end
    Don't know if I am using the proper syntax in that case?

    BigWorm:
    Also, DON'T USE GOTO, unless you really, really, really have to and even then, you can probably get around it.
    That is the only way I know, how else would that be possible?

  5. #5
    Join Date
    Nov 2004
    Location
    Upstate NY
    Posts
    428

    Default

    Using goto is fine. Anybody who's taken any sort of Programming 101 class has had it pounded into their heads that labels and using "goto" (or "jump") is forbidden. That's because they're taking a programmer's class, not a hobbyist's class.

    It's "bad" for two reasons: first, programs are almost impossible to maintain and/or understand if you use labels and jumps. Second, it inhibits the development of your skill as a programmer -- you learn much more and get much better much faster if you basically forbid yourself to use labels.

    If those things aren't of concern to you, labels are perfectly fine.


    As for the "def attack_routine" you asked about, you're missing an `end' -- you "opened" a `def', then opened a `while', then opened an `if'. All of those require their own `end'.

    There is a concern when defining your own methods (what `def attack_routine' is doing): every time you call a method, the return position has to be saved somewhere. If you call another method inside of the first method, then that second return position in the code has to be saved somewhere as well. Now you have two return positions saved. If the third method calls another method, it happens again. I've seen people write scripts that do this literally thousands of times, and eventually Lich ends up giving them a very cryptic error and killing the script saying "error: stack level too deep." If it happens to you, that's why. Doesn't happen with labels, only methods.
    Last edited by Shaelun; 01-28-2008 at 09:39 PM.
    I visualize a time when we will be to robots what dogs are to humans, and I'm rooting for the machines. -- Claude Shannon

  6. Default

    Thanks for the background. I would of course like to learn proper syntax. Was the rest of the code correct besides that end?

  7. #7
    Join Date
    Nov 2004
    Location
    Upstate NY
    Posts
    428

    Default

    Yep, it's fine. You're performing almost identical actions on two branches of your `if/elsif' code, but that's harmless
    I visualize a time when we will be to robots what dogs are to humans, and I'm rooting for the machines. -- Claude Shannon

Similar Threads

  1. Replies: 2
    Last Post: 01-06-2014, 07:14 PM
  2. Replies: 9
    Last Post: 10-29-2012, 09:05 PM
  3. 1003 Lich Script
    By TheOne in forum Bard
    Replies: 15
    Last Post: 10-11-2012, 11:34 AM
  4. Lich script help
    By Rolis in forum Scripting Discussion
    Replies: 1
    Last Post: 11-24-2011, 07:38 PM
  5. How do I run a wiz/sf script with lich?
    By Tenzle in forum Scripting Discussion
    Replies: 1
    Last Post: 05-14-2007, 10:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •