Page 1 of 1

IF Question

Posted: 2004-06-28 07:42:30
by clagio
i noticed a thing and i can't explain why is it..

i have this script:

sub test()
WHILE UO.Life > 0
poison = UO.Poisoned()
IF poison == 1
UO.Cast('Cure','self)
ELSE
wait(5000)
ENDIF
WEND
end sub

In the case of poison different from 1( wait(5000) it doesn't matter if i set 100, 200 or 10000), my client go slowly.. as lag..
if i'm poisoned i go perfectly


if i change in this i move perfectly always:

sub test()
WHILE UO.Life > 0
poison = UO.Poisoned()
IF poison == 1
UO.Cast('Cure','self)
ENDIF
wait(5000)
WEND
end sub

Posted: 2004-06-28 14:48:29
by Yoko
this is a very very often happends logics mistake

note then script

Code: Select all

while ...
  if <false> then
    ....
  end if
wend

is equivalent to

Code: Select all

while ...
wend


Empty cylce will consume all CPU.

for any script you think may produce empty cycle it is safe and reliable to add wait(50) command before second operator bracket (wend, next, until, goto)

for instance your script may look like:

Code: Select all

sub test() 
WHILE UO.Life > 0
poison = UO.Poisoned()
IF poison == 1
UO.Cast('Cure','self)
ELSE
wait(5000)
ENDIF
wait(50) ### !
WEND
end sub

Posted: 2004-06-28 18:38:48
by clagio
IF poison == 1
UO.Cast('Cure','self)
ELSE
wait(5000)
ENDIF

i never had the empty cycle..if im'not poisoned, it should go to the ELSE (wait 5000), no?

Posted: 2004-06-28 20:02:07
by Yoko
IF you poisoned, where is delay? no delay ~= empty cycle

Posted: 2004-06-28 20:04:02
by Yoko
even more, i just noticed, you flooding server with casts using such script you wrote, cause many many times per second, without delay you trying to cast Cure when you are poisoned

Posted: 2004-06-28 20:18:52
by clagio
sorry i can't explain very well :P

i go slowly only when i'm not poisoned :)
this is strange for me.. cause i use a big delay(5000), but it doesn't matter what delay i use

Posted: 2004-07-22 10:36:18
by voyta
If you are uncertain whhat happens in your script, do some debug messages... it'll show ya the problem.


Code: Select all

sub test() 
WHILE UO.Life > 0
poison = UO.Poisoned()
IF poison == 1
UO.print("TRUE, casting")
UO.Cast('Cure','self)
ELSE
UO.print("FALSE, waiting")
wait(5000)
ENDIF
wait(1000) ### just to slow down all the script and avoid message flood.
WEND
end sub


btw: what the heck is IF without THEN ? Parser should Yell about it!
btw2: what is "poison=" ment to be, when there is no "var poison" before? HA :)
btw3: it is ABSOLUTELY useless, you can write "IF UO.Poisoned() THEN" instead