Page 1 of 1
question get bag item count
Posted: Fri Jan 14, 2011 4:05 am
by swietlowka
when i use:
Code: Select all
occupiedSlots, totalSlots = sendMacro("GetBagCount();");
sometimes i get an error that i cannot sompare unmber with nil value, since i use it like this:
the only thing that vould be nil is occupiedSlots... so my question is can i use it like that for this purpose
Code: Select all
local occupiedSlots = sendMacro("GetBagCount();"); repeat until occupiedSlots
will that fix those errors? i dont use totalSlots anywhere... is it needed there?
Re: question get bag item count
Posted: Fri Jan 14, 2011 5:08 am
by jduartedj
swietlowka wrote:when i use:
Code: Select all
occupiedSlots, totalSlots = sendMacro("GetBagCount();");
sometimes i get an error that i cannot sompare unmber with nil value, since i use it like this:
the only thing that vould be nil is occupiedSlots... so my question is can i use it like that for this purpose
Code: Select all
local occupiedSlots = sendMacro("GetBagCount();"); repeat until occupiedSlots
will that fix those errors? i dont use totalSlots anywhere... is it needed there?
What you want should be this:
Code: Select all
repeat local occupiedSlots = sendMacro("GetBagCount();"); until occupiedSlots
but why not use
?
this counts empty spaces!
Re: question get bag item count
Posted: Fri Jan 14, 2011 5:09 am
by swietlowka
lol never though of that lol...
but is
error proof? i mean like nil value or such?
Re: question get bag item count
Posted: Fri Jan 14, 2011 5:12 am
by jduartedj
swietlowka wrote:lol never though of that lol...
but is
error proof? i mean like nil value or such?
Guessing it was done by a developer I'd say YES! Never gave me 1 error... ever!
Re: question get bag item count
Posted: Fri Jan 14, 2011 5:17 am
by lisa
Just wanted to point out u are better off using > and not <, it can mess up
Even though this won't help your problem, it is good to know.
Re: question get bag item count
Posted: Fri Jan 14, 2011 5:41 am
by swietlowka
was posting out of head without my script ofc i have 60 > blah blah, and i would use reapet local blah blah,
nice to know it doesnt give errors

ill test that out tonight :d
Re: question get bag item count
Posted: Fri Jan 14, 2011 7:19 am
by rock5
jduartedj wrote:Code: Select all
repeat local occupiedSlots = sendMacro("GetBagCount();"); until occupiedSlots
That should be
Code: Select all
local occupiedSlots
repeat occupiedSlots = sendMacro("GetBagCount();"); until occupiedSlots
Otherwise the 'occupiedSlots' value wont leave the 'repeat' loop.
swietlowka wrote:lol never though of that lol...
but is
error proof? i mean like nil value or such?
Any functions that read values from memory are more reliable. sendMacro (and RoMScript) can, as you've discovered, sometimes fail and return nil. So if you are ever using them and nil is not a possible value then use the repeat loop trick above. Although it might be better to use "until thevalue ~= nil" to cover functions that return true or false.