Coder Social home page Coder Social logo

Comments (4)

x87 avatar x87 commented on August 20, 2024

It may happen if the model (modelId) was not loaded. Can you show loadModel?
also what do you mean as "async mode"? I don't see any async/await keywords in this code.

from cleo-redux.

Matixk avatar Matixk commented on August 20, 2024
export const loadModel = (modelId: number) => {
    Streaming.RequestModel(modelId);

    while (!Streaming.HasModelLoaded(modelId)) {
        wait(250);
    }
}

It's ok when it's like:

    while (true) {
        wait(250);

        if (Pad.IsKeyPressed(KeyCode.F1))
           spawnCar(CAR_ID);
    }

but when I use it in an async loop then the game freezes:

(async () => {
    while (true) {
        await asyncWait(250);

        if (Pad.IsKeyPressed(KeyCode.F1))
            spawnCar(CAR_ID);
    }
)();

from cleo-redux.

x87 avatar x87 commented on August 20, 2024

you can't use wait in async scripts. rewrite loadModel to be an async function and use asyncWait


export const loadModel = async (modelId: number) => {
    Streaming.RequestModel(modelId);

    while (!Streaming.HasModelLoaded(modelId)) {
        await asyncWait(250);
    }
}


async function spawnCar(modelId: number) {
    log('spawnCar: loadModel ' + new Date().toTimeString());
    await loadModel(modelId);

    log('spawnCar: create car' + new Date().toTimeString());
    // Car.Create this freeze game
    this.currentCar = Car.Create(modelId, this.playerPos.x, this.playerPos.y, this.playerPos.z);
    log('spawnCar: after create car' + new Date().toTimeString());

    log('spawnCar: MarkModelAsNoLongerNeeded ' + new Date().toTimeString());
    Streaming.MarkModelAsNoLongerNeeded(modelId);
    log('spawnCar: end ' + new Date().toTimeString());
}

(async () => {
    while (true) {
        await asyncWait(250);

        if (Pad.IsKeyPressed(KeyCode.F1))
            await spawnCar(CAR_ID);
    }
)();

from cleo-redux.

Matixk avatar Matixk commented on August 20, 2024

Sorry, I've copied the latest script where I've removed all async methods.

I've copied and pasted your code with asyncWait and the problem still occurs:
image

Vice City DE and San Andreas DE works correctly 🤔

from cleo-redux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.