rednode API - v0.50.0
    Preparing search index...

    Variable worldConst

    world: {
        available(): Promise<boolean>;
        entity(id: string | EntityId): Promise<GameRef | null>;
        files(entity: string | GameRef | EntityId): Promise<EntityFiles>;
        load(
            scene: string | Scene,
            options?: { name?: string },
        ): Promise<LoadResult>;
        move(
            id: string | EntityId,
            position: WorldPoint,
            orientation?: WorldRotation,
            yaw?: number,
        ): Promise<boolean>;
        near(options?: NearOptions): Promise<NearEntity[]>;
        on(name: EntityEventName, handler: (event: GameEvent) => void): () => void;
        onRespawn(handler: (before: EntityId, after: EntityId) => void): () => void;
        remove(id: string | EntityId): Promise<boolean>;
        spawn(options: SpawnOptions): Promise<Spawned>;
        spawned(): SpawnedEntry[];
        unload(name: string): Promise<number>;
        watch(id: string | EntityId): Promise<boolean>;
    } = ...

    Entities in the world, for builders and anything that places things.

    Type Declaration

    • available: function
      • True when REDnode's world support runs: Codeware is installed and a game is loaded.

        Returns Promise<boolean>

    • entity: function
    • files: function
    • load: function
      • Loads an EDGEbuilder scene into the running game: its meshes, entities and NPCs (lights are not spawned yet). Pass the scene, or a .scene.json file's path (absolute, or in your package's folder). People stand where placed and stay friendly to V. Loading a scene of the same name again replaces it.

        Parameters

        • scene: string | Scene
        • options: { name?: string } = {}

        Returns Promise<LoadResult>

        const r = await world.load("scenes/my_alley.scene.json");
        // later
        await world.unload(r.name);
    • move: function
      • Places an entity. Cheap enough for once a frame, while the player drags it. For this package's own spawns it also keeps the new place, so a respawn after an archive swap puts the entity where it was moved to.

        Parameters

        Returns Promise<boolean>

    • near: function
      • The entities near V, nearest first, read in the game in one call. With files, each one's files; with uses, only the ones that use one of the given files.

        Parameters

        Returns Promise<NearEntity[]>

        const users = await world.near({ radius: 30, uses: ["base\\environment\\decoration\\containers\\cages\\vending_machine_cage\\vending_machine_cage_b.mesh"] });
        
    • on: function
      • Calls the handler for an entity event of REDnode's entities and watched ones. The event has entityId and entityType. Returns a function that stops it.

        Parameters

        Returns () => void

    • onRespawn: function
      • Calls the handler when REDnode spawned one of this package's entities again, with its old and new id. It does so after an archive swap that changed a file the entity uses, so the entity shows the new version (see archives.reload). Returns a function that stops it.

        Parameters

        Returns () => void

    • remove: function
    • spawn: function
      • Spawns an entity and resolves once it is in the world (Codeware's Entity/AfterAttach). Components are attached while it assembles, before the game gathers its components, the moment Codeware documents for it.

        Parameters

        Returns Promise<Spawned>

    • spawned: function
    • unload: function
      • Removes what world.load spawned for that scene. Resolves with how many were removed.

        Parameters

        • name: string

        Returns Promise<number>

    • watch: function
      • Entity events for an entity spawned elsewhere (by its ID), as world.on delivers them.

        Parameters

        Returns Promise<boolean>

    import { api, world } from "rednode";

    const mesh = await api.$new("entMeshComponent", {
    name: "crate",
    mesh: "base\\environment\\props\\crate_a.mesh",
    meshAppearance: "default",
    });
    const { id } = await world.spawn({
    template: "base\\spawner\\empty_entity.ent",
    position: { x: -1234, y: 987, z: 12 },
    components: [mesh as GameRef],
    });
    await world.move(id, { x: -1234, y: 988, z: 12 }, undefined, 90);
    await world.remove(id);