IF Question

General Injection issues

Moderators: Murderator+, Murderator

Post Reply
clagio
Posts: 58
Joined: 2004-05-09 19:53:49

IF Question

Post 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
Yoko
Site Admin
Posts: 1964
Joined: 2004-04-03 16:49:38
Contact:

Post 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
clagio
Posts: 58
Joined: 2004-05-09 19:53:49

Post 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?
Yoko
Site Admin
Posts: 1964
Joined: 2004-04-03 16:49:38
Contact:

Post by Yoko »

IF you poisoned, where is delay? no delay ~= empty cycle
Yoko
Site Admin
Posts: 1964
Joined: 2004-04-03 16:49:38
Contact:

Post 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
clagio
Posts: 58
Joined: 2004-05-09 19:53:49

Post 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
voyta
Posts: 7
Joined: 2004-06-23 20:56:02
Contact:

Post 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
Post Reply