Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Laradel

Pages: [1]
1
Scripting Tutorials / Brackets and boolean multiplying. Tutorial.
« on: March 24, 2012, 02:05:38 PM »
Hello.

I trully hope that the material of this article can be usefull even for those who have a long easyuo programming practice, because most of this 'features' are undocumented and were found by chance :)

General statement:
The scripts IMHO can be put into two groups:
 a) educational (classic) and which will be supported\watched\inspected by someone else and
 b) 'wild' ones - where perfomance is the main target.

So i'll try to show you that 'wild' way :) wich in my case doesn't brake the main programming rules but uses some rarely used possibilities, some 'wild' tricks and compressed style - 'code in code'.


Part 1. Brackets and boolean multiplying.

Every bracket line in easyuo is considered to be a separate line and processed as a separate line.
So the #lpc cicle is reduced by the amount of bracket lines. If #lpc is 10 and we have 10 lines in a script, where 2 are brackets, the total script performance will go down 20% (theoretically), because only 8 lines are actually 'usefull' in a script and the delay after processing 10 lines (#lpc 10) will happen anyway.

Test example:
Code: [Select]
set #lpc 10  ;default
;set #lpc 200
set %iter 100

set %t1 #SYSTIME
for %i 1 %iter
{
 if %i < 50
 {
 set %return1 bla-bla
 }
 else
 {
 set %return1 bla-bla2
 }
}
set %t1 #SYSTIME - %t1

set %t2 #SYSTIME
for %i 1 %iter
{
 if %i < 500
  set %return2 bla-bla
 else
  set %return2 bla-bla2
}
set %t2 #SYSTIME - %t2

halt

For my PC the results are following:
#lpc 10 :  %t1=3547 - %t2=2594ms
#lpc 200:  %t1= 215 - %t2= 157ms
That speed test is not 100% accurate, because we have "for %i 1 %iter {}" in both cases which consumes the same amount ot lines.

So the brackets may not be used in following structures if you want to encrease the perfomance of your script:


for %i 1 100
 One line only, for more lines you will need brackets


while bCondition
 One line only, for more lines you will need brackets


repeat       ; brackets may not be used
 code block1
 code block2
 code block3  
 code block4
until


if bCondition
 one line of code


if bCondition
 one line of code
else
 one line of code


if bCondition 3      ; 3- you set how many lines to pass if bCondition=#false
 line 1
 line 2
 line 3
else 2               ; same here: you set how many lines should the script pass after
 line 1              ; execution of the 'true block' (bCondition=#true)
 line 2


if bCondition N      ; N lines of code
 line 1
 line 2
  ...
 line N


So you can make such construction without brackets:
Code: [Select]
if a>b 5    ; <- 5 here is the next 5 lines
 if a>c     ; 1
    line 1  ; 2
 else 2     ; 3
    line 1  ; 4
    line 2  ; 5
else 7      ; <- 7 here is the next 7 lines
 if a>c 2   ; 1
    line 1  ; 2
    line 2  ; 3
 else 3     ; 4       <-else 3  - 3 here is the next 3 lines
    line 1  ; 5
    line 2  ; 6
    line 3  ; 7

In this example we have cutted 12 brackets and got fast, but hardly readable and updateble code.
The main problem is when you\someone start editing watch the line shift indexes after if\else.
I personally do not recommend to 'pack' code cutting brackets before it's completely done.


Can the line shift index after IF be negative? yes

have a look on example:

Example 2:
Code: [Select]
set %timeout #SYSTIME + 5000   ; set timout current time + 5 secs
if %timeout < #SYSTIME -1         ; wait until timout

Warning! "#SYSTIME -1" in the last line not "#SYSTIME - 1",  "-1" - is a line shift index.
I other words it checks the condition if %timout already less than current time? if yes, then it will go to th next line after 'if' statement if

not, then it will take the current shift index and go according it.

Example 3:
Code: [Select]
gosub Send_party_chat Help_i'm_dead: , #CHARPOSX , _ , #CHARPOSY , _ , #CURSKIND  ;<----+
 gosub Check_Is_Someone_Going_to_resurect_me                                                       ;       |
 wait 20                                                                                                               ;       |
if #CHARGHOST = no -4                                                                                         ;>----+
 gosub Send_party_chat I'm_Alive!Ehha!
This code rotate until you'll be resurected :)

Example 4: (you'll find it in my Subs):
Code: [Select]
if #false ( %0 * -2 * ( %0 < 9 && _ , %1 , _ in _SubName1_SubName2_SubNameN_ ) )
 set #result Error_No_such_sub
 exit
 gosub %1
 exit
 gosub %1 %2
 exit
 gosub %1 %2 %3
 exit
 gosub %1 %2 %3 %4
 exit
 gosub %1 %2 %3 %4 %5
 exit
 gosub %1 %2 %3 %4 %5 %6
 exit
 gosub %1 %2 %3 %4 %5 %6 %7
 exit
 gosub %1 %2 %3 %4 %5 %6 %7 %8
 exit

Looks wild? :) but it works perfect and very fast. The purpose is to redirect incoming request to the appropriate sub in the subs library (all small subs are in a one file)
call Library.euox %SubName %parametr1 %parametr2 ... %parametrN
Any Sub can receive up to 7 parameters in this example.
Here comes another 'wild' aspect that works in easyuo - multiplying boleans and integers :)

#true is -1 and #false is 0.

Lets have a look on the first line in details.

if #false ( %0 * -2 * ( %0 < 9 && _ , %1 , _ in _SubName1_SubName2_SubNameN_ ) )
      a)          e)    d)  +- b) --+ +--------- c) ---------------------------+          

a) always #false - means to force script use line shift index every time
b) and c) error check bracket:
  b) if #true - 1-7 parameters passed      c) do we have such Sub in our file? - if b) or c) fails we will get #false (what means 0)
otherwise we'll get #true (what means -1).

d) we multiply -2 (number of lines in each sub call) on #true(-1) or #false(0) and get +2 or 0(if error check fails)
e) we calculate the line shift: number of parameters passed * 2 or 0
if d) gives us 0, the next line in statement  if #false 0   will be  set #result Error_No_such_sub, like there is no 'true' block at all
if d) gives us 2, we have an offset to the gosub with a proper number of parameters to be passed to the final Sub.

More multiplying:

Code: [Select]
set %a #true
set %d 0

if %a           ; %a can be #true or #false - some condition
  set %d %d - 1
esle
  set %d %d + 1


same, but in one line:
Code: [Select]
set %d 1 + %d + %a * 2


Can line shift indexes after ELSE be negative? yes
Example 5:
Code: [Select]
set %a 4
set %b 1
if %a > %b
 set %b %b + 1
else -3

This script will go further only when %b = 4.


Probably that's all for today post. Next part may be about strings in every day life :)
Please let me know if you like this post or not.
May be i'm just trying to tell you something evident and well known?  :'(

Thanks for reading. And sorry for my EnGliSh :)

2
New member introductions / Greetings ScriptUO!
« on: March 24, 2012, 05:21:27 AM »
I'm 36 male and i'm from Ukraine. Native language - russian\ukrainian. Location - Crimea.
My UO experience started in late 1999 when i was lumberjacking manually for hours on the one of leading UA shards "LOL" :)  I was always playing on freeshards and was far away from any coding for UO (even didn't knew it's possible). Then it was i big pause, i switched to Q1TF, WoW later and ETQW after that. But "Ultima Call" :) was raising it's head more often and often, so i got a new client installed and have found that (eha!!) now all items have properties visible (ML), and start playing. Aproximately at the same time i've found and join easyuo community - as a reader mostly. Start doing simple codes, learn how they are done from the other scripts.

Before this it was evident for me that my hobby is programming. I never worked as programmer though - i'm manager now, but was doing some VBA for Excell code,foxpro, asm etc. So easyuo became a brilliant combination of 2 hobbies: gaming favourite UO and coding! So at the moment i can say i'm coding easyuo for 6-7 years. Since i was sure it's the best way to code for UO i've never been searching for something else. Now it's switching to openEUO with lua which i don't actually like taking into account that's it's unfinished yet. So i start looking for something else and OMG! stealth! :) and  ??? the motherland is Odessa-Ukraine (great job!). So i'm in the process of switching to stealth\python now(best regards to my friend Crome696 who showed me stealth and SciptUO community too).

In game i'm more scriptor than player :) and now i'm a stuff member of one of the greatest freeshards, hope soon will have an access to development section to participate in runuo development.

For some reason i was never (twice only on easyuo forum) posting my scripts and subs. So probably they were waiting for this moment :)
I'm gonna post some which are Subs and can be used by any level of easyuo developers in creating their scripts.

That's all story. Do you mind my joining ScriptUO community?

Pages: [1]