Page 1 of 1

New trick for advanced users

Posted: Thu May 22, 2014 6:46 am
by rock5
Some of you will be aware that doing 1 RoMScript is a lot faster than doing multiple RoMScripts. So it's better to do loops in the game than in the bot. Here's an example, say you want to see if you have a particular title. A really slow way would be like this

Code: Select all

for i = 0, RoMScript("GetTitleCount()") do
    local name, titleid, geted = RoMScript("GetTitleInfoByIndex("..i..")
    if titleid == 530897 then 
        -- have title
        break
    end
end
On my character with 568 titles this takes nearly 2m.

People with the programming skills know this can be done with an in game loop that will be much faster, example

Code: Select all

RoMCode("for i = 0, GetTitleCount() do n,t,g=GetTitleInfoByIndex(i) if t==530897 then a = {g} end end")
Until recently the length of this command was limited to 255 characters and it didn't matter if you used the whole 255 characters it still took about the same amount of time.

Now RoMScripts can be any length. This is useful because now you can create long complex code and execute it in 1 RoMScript. A side affect of this is if the command is longer than 255 characters it will take twice as long. If it's more than 510 characters it will take 3 times as long, etc. So the usefulness of using really long code will be limited by how long it will take.

The trick I want to introduce is creating an in game function instead. When you want to use some really long code it might be beneficial to do something like this.

In the onload of your waypoint file create the in game function.

Code: Select all

RoMCode([[
    function myfunction(arg)
    
        ...    
    
        ...    

        -- some really long code
    
        ...    

    
        ...    

    end
]])
Then when you need to run the code just use this which should run fast as any short RoMScript would.

Code: Select all

RoMScript("myfunction("..argument..")")
Well, that's it. There might not be much call for it but it's worth keeping in mind.