Jump to content
UBot Underground

Noob questiion- about next list item..


Recommended Posts

Hi guys,

 

Please take a look at the code below - the 'Load Html' command has a 'next list item' function in it - which should print the list item to  the browser window -one after the other- but I find that the next list item does not  execute the second time onwards in the loop - please .. if anyone could tell me what am I doing wrong?

 

I can make the code work with the  'list item' function - but I want to know what is wrong with my coding here..

 

Thanks.

set list position(%ouputtoscreen, 0)
clear list(%ouputtoscreen)
set(#flag, $false, "Global")
set(#ctr, 0, "Global")
add item to list(%ouputtoscreen, "before loop starts  value of ctr is  = {#ctr}", "Delete", "Global")
loop while($not(#flag)) {
    increment(#ctr)
    add item to list(%ouputtoscreen, " After loop {#ctr} value of loopctr is  = {#ctr}", "Delete", "Global")
    load html($next list item(%ouputtoscreen))
    add item to list(%listPos, $list position(%ouputtoscreen), "Delete", "Global")
    wait(.5)
    if(#ctr >= 5) {
        then {
            set(#flag, $true, "Global")
        }
    }
}
Link to post
Share on other sites

You are confused ... you are using both increment AND $next list item which is wrong.

I keep telling people on this forum that the best way to loop lists (except the very very simple, clear number of steps loops) is to STOP using $next list item and start using $list item instead.

 

The difference between these two commands is that with $list item, you have to specify the EXACT index where you want the item to be retrieved from the list.

 

$next list item does a similar thing, but IN THE BACKGROUNDS, it ALSO MOVES THE INDEX FORWARD ONE STEP!!!

People usually are not even aware that thing happens and they get lots of errors, especially at the end of the loop, when the index tries to jump outside the bonds of the list...

 

So make a choice now...

 

Keep using increment with $list item though... (the best way)

OR

use $next list item, but lose the increment and the LOOP WHILE and use a LOOP instead.

 

Hope this helps you.

Link to post
Share on other sites

@VaultBoss -Iam aware of what next list item does, also if you see the code -you will notice that the ctr I am using does not disrupt the loop or the list pos.

 

I am not using the ctr to increment the list position .It simply keeps count of the number of loops executed.

 

All I want to know is - why doesn't the next list item execute as it should?

 

Thanks.

Edited by Sanjeev
Link to post
Share on other sites

Change your code to this:

    load html($list item(%ouputtoscreen, #ctr))

instead of this

load html($next list item(%ouputtoscreen))

...and it will work.

 

You can either follow my advice and stop using $next list item altogether, or not.
Your choice

Link to post
Share on other sites

Thanks for your help VaultBoss , I highly appreciate it!

 

I understand what you are trying to say - that when creating bots - list item is much more reliable..where as next list item can throw up errors as it moves the list pos down every time its called..so you never know when you have exceeded your range...

In the above situation ,I just don't understand why next list item doesn't execute? Though..according to me it should...!

Anyone..?

Link to post
Share on other sites

When you added a new item to list inside the cycle, you basically moved the list index to point to that last item you added.

 

Say, initially the list index was 0 (you added the first item outside the loop)

Inside the cycle, the next list manipulation you perform is to add yet another list item (will take position with index # 1 now)

 

AFTER that, you load that list item correctly with the first load html BUT AT THE SAME TIME the list index is moving forward, now pointing to item #2 (non-existent yet, but it doesn't affect program flow because you're not doing anything with it yet)

 

However, when repeating the cycle, you now add again this new list item that you create, to the CURRENT position in the list index (that was previously set by $next list item) + 1 >>> so now, the list index will be pointing to 2+1=3 and the index #2 is left empty...

 

When you try calling that list item to display with load html, there is an empty item there (pos #2) so nothing to display, while the command itself also increment moving forward once again... and so forth...

 

As you can see, the logic flow will become harder and harder to follow - which is why I said, just DUMP that command already and simply use $list item instead which gives you perfect positioning and control.

 

Just sayin'...

  • Like 1
Link to post
Share on other sites

Wow! Thanks bro - I will need to study what you just wrote a bit more - for it to sink in completely ..thanks a lot!

You Rock!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...