PDA

View Full Version : Lich script help



Flessen
01-28-2008, 03:00 PM
Would this be a logical routine?


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

BigWorm
01-28-2008, 03:04 PM
That's not how you use the comma operator. You want to do:

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).

BigWorm
01-28-2008, 03:05 PM
Also, DON'T USE GOTO, unless you really, really, really have to and even then, you can probably get around it.

Flessen
01-28-2008, 03:52 PM
BigWorm:
That's not how you use the comma operator. You want to do:


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?


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?

Shaelun
01-28-2008, 09:34 PM
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.

Flessen
01-28-2008, 09:39 PM
Thanks for the background. I would of course like to learn proper syntax. Was the rest of the code correct besides that end?

Shaelun
01-28-2008, 09:42 PM
Yep, it's fine. You're performing almost identical actions on two branches of your `if/elsif' code, but that's harmless :)