• Categories
  • Recent
  • Popular
  • Users
  • Search
  • FingerprintSwitcher
  • CustomServers
  • AutomationPlugins
Skins
  • Light
  • Default
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Quartz
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Slate
  • Solar
  • Superhero
  • Vapor
Collapse

Bablosoft

Global Variable is not increasing on each new thread

Scheduled Pinned Locked Moved Support
7 Posts 2 Posters 1181 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ev0
    wrote on last edited by
    #1

    I'm having a weird issue all of a sudden:

    I set global variable before creating threads. Let's say value of 5 (int).

    I create 10 threads, and wish to have each thread increase it by 1, so I "Increase global variable" at the start of the thread function, but each thread uses the 6 value, not 6,7,8,9,10, etc...

    Before "Call function in several threads":
    9b3ebc7c-2e6d-4f36-a622-d7aca8dead44-image.png

    Inside the fucntion:
    56e3a53c-4f4f-4d66-b246-6248baa169ce-image.png

    Output when ran:
    alt text

    1 Reply Last reply
    0
  • GaGG Offline
    GaGG Offline
    GaG
    wrote on last edited by
    #2

    Why you use "Call function in several threads"?

    If you use it for increasing global or local variable
    it will probably increase just once, since its just ONE
    function call - so it works as expected

    Use "Thread number" instead and set it to number you need.
    Than increasing of number should work fine.

    1 Reply Last reply
    0
  • E Offline
    E Offline
    ev0
    wrote on last edited by
    #3

    @GaG said in Global Variable is not increasing on each new thread:

    Why you use "Call function in several threads"?

    If you use it for increasing global or local variable
    it will probably increase just once, since its just ONE
    function call - so it works as expected

    Use "Thread number" instead and set it to number you need.
    Than increasing of number should work fine.

    Thanks for your reply. I attempted to increase thread number at the top, and just calling the function in each thread. However, no luck.

    So I guess, for some reason, my brain is blocking logic; are you referring to:

    3509f31d-ffdb-4e87-8281-85ca2bd63d39-image.png

    1 Reply Last reply
    0
  • GaGG Offline
    GaGG Offline
    GaG
    wrote on last edited by GaG
    #4

    Yes, but dont use "Call function in several threads". Just
    increase number inside your script. So your script would
    execute 10 times and in each execution it will increase global var by 1.

    1 Reply Last reply
    1
  • E Offline
    E Offline
    ev0
    wrote on last edited by ev0
    #5

    This method did not work for me. Do you see something I'm doing wrong?

    (with a increase global variable inside that function)

    Still outputs all same number.

    8f3066e7-fc09-411b-8d7e-8f1efd98f54b-image.png

    1 Reply Last reply
    0
  • GaGG Offline
    GaGG Offline
    GaG
    wrote on last edited by
    #6

    Set global variable as function with option "OnAplicationStart"
    That way it will set starting number only once.

    In your current code it resets to starting value on every thread execution.
    Maybe it was the case even with "Call function in several threads", test it.

    1 Reply Last reply
    1
  • E Offline
    E Offline
    ev0
    wrote on last edited by
    #7

    I got it, with some other logic.

    I had to redefine global variable while inside the thread, then increase it.

    1 Reply Last reply
    1

  • T

    How to use variable inside call function in serveral threads

    Scheduled Pinned Locked Moved Support
    0 Votes
    1 Posts
    375 Views
    No one has replied
  • F

    I can't create variable names

    Scheduled Pinned Locked Moved Support
    0 Votes
    1 Posts
    306 Views
    No one has replied
  • P

    Deleting the database while other threads are active

    Scheduled Pinned Locked Moved Support
    0 Votes
    2 Posts
    420 Views
    No one has replied
  • R

    Save data when thread crashes

    Scheduled Pinned Locked Moved Support
    0 Votes
    1 Posts
    372 Views
    No one has replied
  • Y

    (resources) Lines in text file dont get removed after thread finish but they do after script finish

    Scheduled Pinned Locked Moved Support
    0 Votes
    1 Posts
    1114 Views
    No one has replied
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Popular
  • Users
  • Search
  • FingerprintSwitcher
  • CustomServers
  • AutomationPlugins
  • Login

  • Don't have an account? Register

  • Login or register to search.