Sanjeev 46 Posted January 23, 2014 Report Share Posted January 23, 2014 Hi guysIn 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. Quote Link to post Share on other sites
Bot-Factory 602 Posted January 23, 2014 Report Share Posted January 23, 2014 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 Quote Link to post Share on other sites
Sanjeev 46 Posted January 23, 2014 Author Report Share Posted January 23, 2014 Oh wow! thanks! How stupid of me. Quote Link to post Share on other sites
UBotDev 276 Posted January 23, 2014 Report Share Posted January 23, 2014 Hi guysIn 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). Quote Link to post Share on other sites
Sanjeev 46 Posted January 24, 2014 Author Report Share Posted January 24, 2014 Thanks UbotDev! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.