Jump to content
UBot Underground

A vey basic question.. Why is this happening...


Recommended Posts

Hi guys

In the code below -

I created a list from text , and then call a define from within a thread.

Inside the define - I am simply adding the  list item at index 0 - 5 times to a new list (I have set the new list  to - 'do not delete duplicates').

clear list(%Numbers)
clear list(%NewNumbers)
add list to list(%Numbers, $list from text("1,2,3,4,5,6,7,8,9", ","), "Delete", "Global")
set(#NumberRow, 0, "Global")
thread {
    getNumbers(#NumberRow)
}
load html(%NewNumbers)
stop script
define getNumbers(#NumberRow) {
    loop(5) {
        add item to list(%NewNumbers, $list item(%Numbers, #NumberRow), "Don\'t Delete", "Global")
    }
}

This give me a new list with contents as follows - 11111

 

But if i were to add an additional wait command or alert command inside  the the loop -

clear list(%Numbers)
clear list(%NewNumbers)
add list to list(%Numbers, $list from text("1,2,3,4,5,6,7,8,9", ","), "Delete", "Global")
set(#NumberRow, 0, "Global")
thread {
    getNumbers(#NumberRow)
}
load html(%NewNumbers)
stop script
define getNumbers(#NumberRow) {
    loop(5) {
        add item to list(%NewNumbers, $list item(%Numbers, #NumberRow), "Don\'t Delete", "Global")
        wait(2)
    }
}

My new list's contents are  only a single -1.

 

Why is this happening?

 

Thanks.

Link to post
Share on other sites

You just have to remove "stop script".

 

The thread command is executed and running parallel to your bot. 

And because of the wait command, the thread takes longer than without wait.

And therefore the bot reaches the stop script command. Which will also stop the thread before it's finished.

 

Dan

Link to post
Share on other sites

Hi guys

In the code below -

I created a list from text , and then call a define from within a thread.

Inside the define - I am simply adding the  list item at index 0 - 5 times to a new list (I have set the new list  to - 'do not delete duplicates').

clear list(%Numbers)
clear list(%NewNumbers)
add list to list(%Numbers, $list from text("1,2,3,4,5,6,7,8,9", ","), "Delete", "Global")
set(#NumberRow, 0, "Global")
thread {
    getNumbers(#NumberRow)
}
load html(%NewNumbers)
stop script
define getNumbers(#NumberRow) {
    loop(5) {
        add item to list(%NewNumbers, $list item(%Numbers, #NumberRow), "Don\'t Delete", "Global")
    }
}

This give me a new list with contents as follows - 11111

 

But if i were to add an additional wait command or alert command inside  the the loop -

clear list(%Numbers)
clear list(%NewNumbers)
add list to list(%Numbers, $list from text("1,2,3,4,5,6,7,8,9", ","), "Delete", "Global")
set(#NumberRow, 0, "Global")
thread {
    getNumbers(#NumberRow)
}
load html(%NewNumbers)
stop script
define getNumbers(#NumberRow) {
    loop(5) {
        add item to list(%NewNumbers, $list item(%Numbers, #NumberRow), "Don\'t Delete", "Global")
        wait(2)
    }
}

My new list's contents are  only a single -1.

 

Why is this happening?

 

Thanks.

You didn't do your homework young boy! :)

 

This happens because of the reason I told you here (thread running in parallel). In your code with delay thread gets executed in parallel with the main code, and before the 2nd element is added to your display list, command "load html" fires and displays only 1st number in your browser. At that point thread is still running (probably delaying) and later adding 2nd, 3rd,... item to the list, so if you check debugger at the end (after removing stop) you should see all numbers there (but they are not displayed since "load html" is executed before list was populated).

 

To fix this you need to wait for parallel process/thread to finish, and only then display data (when the list is ready).

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...