Jump to content



Photo

Variables Inside Threads

thread

  • Please log in to reply
2 replies to this topic

#1 ohsnap

ohsnap

    Newbie

  • Fellow UBotter
  • Pip
  • 6 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 23 March 2015 - 06:31 PM

Can somebody please shed some light onto UBot's stange looping / threading behavior?

 

When I run the following code, I get three alerts: 1, 2, and 3. (Strange that it's not 0,1, and 2, but that's besides the point).

 

set(#loopCounter,0,"Global")
loop(3) {
    thread {
        alert(#loopCounter)
    }
    increment(#loopCounter)
}

 

However, when I run the following code (I added "in new browser") my three alerts are all "3"

 

set(#loopCounter,0,"Global")
loop(3) {
    thread {
        in new browser {
            alert(#loopCounter)
        }
    }
    increment(#loopCounter)
}

 

I am trying to keep a variable inside each thread to keep track of that particular thread - but either UBot is not thread safe or I am doing something wrong. Any help greatly appreciated.

 

Thanks



#2 ohsnap

ohsnap

    Newbie

  • Fellow UBotter
  • Pip
  • 6 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 23 March 2015 - 10:08 PM

I found the solution, thanks to Dan in an old thread..

 

http://www.ubotstudi...thread variable

 

 



#3 gavind

gavind

    Advanced Member

  • Members
  • PipPipPip
  • 176 posts
  • OS:Windows 8
  • Total Memory:4Gb
  • Framework:v3.5
  • License:Community Edition

Posted 25 March 2015 - 01:08 PM

The best thing about it too is that he started the thread sharing what he found out. +1 to Dan! smile3.png







Also tagged with one or more of these keywords: thread

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users