Discord
Login
Community
DARK THEME

How to make a new Thread with JS, which dosent block everything else

Hey guys,I have a Problem with creating a new Thread and than calling a js function inside of it.

https://microstudio.dev/i/KingLauri200/4inrowtst122223/

Here I'm calling my bots in the update function, creating a new Thread. The reason? Firstly, I want the Rest of the Code to running seperatly, so I can show the Bots calculations live, and on the other hand, I want to have the option for the Player to start a new Game (SPACE). U can test it, by Playing against V_ONE(JS) or V_TWO(Microscript).

File "2_functions" line 75 - "i" ???

In my opinion, you shouldn't draw anything in the update function. This function is only for calculations. Draw only in draw . I guess you don't need to draw the same scene several times. In the "2_functions" file, the drop function has a .

   drawGB(gb)
   x_db.update(mouse.left)
   o_db.update(mouse.left)

I commented out these lines and the program still draws the boards correctly (meaning these lines are unnecessary).

Don't draw on the screen in threads - at least that's how it is in Windows. Only the main thread should draw, otherwise a collision may occur. One thread starts drawing, the other interrupts it and also starts drawing, changes the settings of some register, stops drawing. The first thread returns to drawing and for 2 days you wonder why the program raises an exception.

Aha - JavaScript is a single-threaded program and you cannot create a new thread in it. MicroScript is cheating a bit by saying that this is a new thread. It has a list of addresses of instructions to be executed in the next update<>draw iteration. When you create a thread, you add another starting point - and possibly the time when it should start.

I ran your program - the bots played with each other (v1 <> v1, v1 <> v2, v2<>v2) and with me, but I didn't see any problem. (FPS dropped to 30 on firefox)

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community