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

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
top1
Posts: 50
Joined: Mon Jan 03, 2011 4:57 pm

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

#1 Post 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
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

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

#2 Post 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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

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

#3 Post 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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan
top1
Posts: 50
Joined: Mon Jan 03, 2011 4:57 pm

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

#4 Post 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
top1
Posts: 50
Joined: Mon Jan 03, 2011 4:57 pm

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

#5 Post 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
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

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

#6 Post 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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan
top1
Posts: 50
Joined: Mon Jan 03, 2011 4:57 pm

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

#7 Post 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
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

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

#8 Post 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. :)
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan
Post Reply