Page 1 of 1

GetBagCount() getting -sometimes- "compare number with nil"

Posted: Wed Feb 02, 2011 12:28 pm
by top1
"GetBagCount();"
leads in some cases to following error:

[string "..."]:3: attempt to compare number with nil


it's a once every 3-4 hour error ~ approximatley
"GetBagCount();" is done every circle (5min)


is this because of a special item in the inventar?
or a special number of items?

no idea :/


hope someone can help

Re: GetBagCount() getting -sometimes- "compare number with n

Posted: Wed Feb 02, 2011 9:33 pm
by rock5
RoMScript sometimes fails and returns nil. That's why in a lot of my scripts I will do something like this

Code: Select all

repeat var = RoMScript("function()") until var ~= nil
This, of course, can only be used if nil is not a possible expected answer.

RoMScript sometimes returns nil because of a 'time out'. I often wondered what would happen if there was no time out but I need someone who can reliably get that error. Would you be willing to try a little experiment for me? If so, please do the following.

Around line 573 of functions.lua you'll see the 'time out' code.

Code: Select all

			if( deltaTime(getTime(), startWaitTime) > 800 ) then
				if( settings.options.DEBUGGING_MACRO ) then
					cprintf(cli.yellow, "[DEBUG] TIMEOUT in RoMScript ... \n");
				end;
				return default; -- Timed out
			end;
Comment out the 'return' and see what happens.

Code: Select all

				-- return default; -- Timed out
If anyone else wants to test this for me please feel free to do so.

Re: GetBagCount() getting -sometimes- "compare number with n

Posted: Thu Feb 03, 2011 3:15 am
by rock5
I figured I never get the nil error because I always use those 'repeat' tricks so I thought I could still test it myself. I also added a bit of code that records what happens for extra info.

The results so far after about 1.5 hours with 2 clients running:
  • 1 got stuck because it didn't action the macro ie. didn't click the action key. This happened twice. I was able to get the bot to continue by clicking the macro key manually. I'm not sure yet what we can do about that. Maybe keep clicking the macro until it works?
  • The second one passed the 800ms threshold twice at around 1150ms but continued on afterward. Both times I would have got the "compare to nil" error if I hadn't done the change above. So in this situation, bypassing the "timeout" worked.
I'll keep testing and maybe try some code to try again if it fails to click the action key.

Re: GetBagCount() getting -sometimes- "compare number with n

Posted: Thu Feb 03, 2011 12:49 pm
by top1
thanks rock5!

I dont know how to use

Code: Select all

repeat var = RoMScript("function()") until var ~= nil
this :(

at the moment I use:

Code: Select all

      
occupiedSlots, totalSlots = sendMacro("GetBagCount();");
if(  occupiedSlots > 52 ) then
__WPL:setWaypointIndex(__WPL:findWaypointTag("SELL"));
   end
:/ do I simply change it to

Code: Select all

repeat var = RoMScript("GetBagCount();") until var ~= nil

anyway,
I commented the timeout thing out, and will test it right now!


thx again!
I'll report back

Re: GetBagCount() getting -sometimes- "compare number with n

Posted: Thu Feb 03, 2011 1:09 pm
by top1
#reports#

-- will be edited on every news --


#1 runntime ~4min

Code: Select all

died in bossfight, script just kind of aborted, 
couldnt even end the micromacro script with strg+l
very strange, no errors, bot both players died
never had something like this before
- sadly didnt watch what exactly happend
#2 runntime 29min

Code: Select all

bot1 stopped working on "LeaveParty()" --> didnt left, didnt continue
bot2 stopped working while "GetNumPartyMembers()" 
maybe both stopped parallel, didnt see it happening live...
#3 runtime 4min

Code: Select all

one loop , both chars walked out of the instance, bot2 left the group
and startet inviting bot1 again, while bot1 got stuck after leaving the instance
on "GetNumPartyMembers()"  again. so he isnt replying, no error, no continue... 

I change the settings back again, and see how long they run until the nil value error now

Re: GetBagCount() getting -sometimes- "compare number with n

Posted: Thu Feb 03, 2011 11:59 pm
by rock5
top1 wrote:thanks rock5!

I dont know how to use

Code: Select all

repeat var = RoMScript("function()") until var ~= nil
this :(
Example:
If you have

Code: Select all

occupiedSlots, totalSlots = sendMacro("GetBagCount();");
You would change it to

Code: Select all

repeat occupiedSlots, totalSlots = sendMacro("GetBagCount();"); until (occupiedSlots ~= nil and totalSlots ~= nil)
With this code you shouldn't get any "compare with nil" errors.

Thanks for the testing you did. With the testing I was able to do, it looks like sometimes, especially while using the computer yourself to do other things, the results can take longer than the 800ms to return, as much as 6 or 8 seconds. Leaving out the timeout fixes that but sometimes it fails to return a value at all because the macro fails to execute. That's when it gets stuck waiting for a response that never comes. We could fix this by trying again but there is the danger that the command could get executed twice and in some situations you wouldn't want that, eg. using an expensive item, but I'm not sure how often that would occur.

I don't know if it would actually execute twice. I'll have to do more testing to find out. But in the mean time, the above should work for you.

Re: GetBagCount() getting -sometimes- "compare number with n

Posted: Fri Feb 04, 2011 11:23 am
by top1
thx!

no nil error anymore!!!!!!!!!!!!!!



but took me a while figuring out how to modifie codes like this:

Code: Select all

repeat groupcheck = sendMacro('GetNumPartyMembers()'); until groupcheck ~= nil;
if groupcheck == 0 then
            repeat
            yrest(2000);
            sendMacro('InviteByName("Spidermann")'); 
            yrest(1000); 
            sendMacro('SetInstanceLevel("easy")');
            repeat groupcheck = sendMacro('GetNumPartyMembers()'); until groupcheck ~= nil;
            until groupcheck == 2
            end

Re: GetBagCount() getting -sometimes- "compare number with n

Posted: Sat Feb 05, 2011 8:46 pm
by rock5
Ok, after extensive testing it looks like I can remove the timeout in RoMScript and have it retry the macro if it fails. It works 100% of the time. The fear I had that it might actually often execute the command more than once in game didn't happen. It will only actually repeat the ingame command 1 in hundreds of retries.

This is looking good to commit. I'll do some cleaning up and maybe just a bit more testing and then I'll release it.

So from now on we wont get 'compare to nil' error any more. :)