Among Us The Game

I was talking about the classmate thing.

1 Like

I am working on it but yet nobody helped me with my issue so currently I can not do anything :confused:

2 Likes

Hey, have you tried using github to save changes, and revert hem if anything goes wrong?

1 Like

No not really

2 Likes

So This kind of disappeared… I still need help!

1 Like

So, path finding is expensive (it takes a lot of time to do, especially on big tilemaps). It looks like every time you are calculating a path, you are actually calculating 7 paths and then randomly choosing one of those.

Instead, you should randomly choose a destination, and then only calculate one path (the one from the current location to that position). If it still feels slow, you can also use the timers extension to put this in the background instead of on game update. That will stop it from pausing the game every time it needs to do something that takes a long time.

That logic would look something like this:

When vx and vy are both 0 and the sprites isn't already looking for a path:
    set is_finding_path to true on the sprite data of the sprite
    inside run separately:
        calculate path
        follow path
        set is_finding_path to false
1 Like

OK thanks! I will do that! Thanks for the Help! I will tell you if there is something wrong

1 Like

Stop path solved! I just set the set kind to body first! Now they stop!

And also I can not stop them when they get killed… I tried setting velocity, acceleration, both, follow emty array and follow path from its position to its position… But they will keep going! They are switching to be kind body so they will not find another path… but they will complete their current one! Also whenever I kill them they just get a new path… And that path is not any path! It is one of my path list! So what I guess is the person gets killed, then its velocity is 0 for a second so they get a new path and then the kind switches! But I will change that!

So I changed it and now it does not lag as hard but there is still notacible lag! What should I do?

(In the beginning they stay for a bit! Then there is one big lag bc everyone gets a path and then everytime someone gets a new path it lags slightly!)

There’s no easy solution to this, unfortunately. @jwunderl should there be a pause in the a-star function? maybe only after the path reaches a set length?

1 Like

Is it about the lag or the stop?

The lag. The easiest way to handle the stop would be to throw up a loading screen while you calculate the first set of paths.

That being said, adding a pause to the extension would probably solve everything. The explanation is a little technical, but here goes:

MakeCode has a concept of multi-threading that we call “fibers”. When you call “separately do”, you are creating a new fiber and telling it to run whatever code you put inside. Now there is more than one fiber in the game (the one you created and the one that is running "on game update). When that happens MakeCode will take turns running them. In other words, it will run the “on game update” for a little bit, then run “separately do” for a little bit, then run “on game update” for a little bit, etc.

However, MakeCode will only switch between fibers if one of them calls the “pause” function. Otherwise it will just let whichever one is currently running run until it finishes.

That’s why you have lag right now: even though the path code is inside of a “separately do”, the a-star extension doesn’t call pause so MakeCode needs to wait for it to finish before it can go back to running the game.

Here is an example project that shows this off: https://makecode.com/_CTKKh6MsCEe7

If you look at the code, it looks like the number should be counting up from 0 to 10000 on the screen. But when it actually runs, it just lags for a while and then shows the number 10000. That’s because the fiber is never pausing so the game can’t update.

If you change the variable “doPause” from false to true, then you will see the number actually count up because the fiber is now letting the game run.

1 Like

Hmmm ok I get it! So des that mean I just have to put a pause there? (Like if true)

No it needs to be done inside the extension, but I’ll leave it up to @jwunderl’s judgement because he wrote the extension.

1 Like

Ok! So I’ll have to wait until it will be updated? Well thanks for your help! It works good… In the beginning it has a big lag and everytime a new one is being calculated there is a small lag… But it is playable! And thats what counts! Thanks

I’m not sure on pausing mid calculation, as I feel like that could cause some weird, hard to explain behavior (e.g. two overlap events storing a temp variable, with the first one calculating a longer path would cause issues) / I wouldn’t expect it to yield to other fibers when calculating something like that personally, but there’s certainly some work that can be done on optimizing the path finding so it runs faster in general – I’ll take a look when I get some extra free time :slight_smile:

1 Like

Ok thanks!

New version

The latest one is further up! I will do changes soon!