REPENTOGON icon indicating copy to clipboard operation
REPENTOGON copied to clipboard

Isaac.CreateTimer runs instantly in MC_POST_NEW_ROOM

Open theMonwil opened this issue 1 year ago • 1 comments

If Isaac.CreateTimer is called in MC_POST_NEW_ROOM callback, it'll fire instantly upon entering the room even with high interval set. Whether the timer is set as persistent or not appears to have no obvious effect. If the function is set to run more than once, it'll fire with the correct delay after the first call.

Reproduction is as simple as running Isaac.CreateTimer in a function called by the MC_POST_NEW_ROOM callback.

local mod = RegisterMod("Test", 1)

local function PostNewRoom()
    Isaac.CreateTimer(function ()
        Isaac.Spawn(
            EntityType.ENTITY_PICKUP,
            PickupVariant.PICKUP_COLLECTIBLE,
            CollectibleType.COLLECTIBLE_SAD_ONION,
            Game():GetRoom():GetCenterPos(),
            Vector.Zero,
            nil
        )
    end, 60, 1, false)
end

mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, PostNewRoom)

Marking as low priority since there's a "good enough" workaround for now of wrapping the CreateTimer in another CreateTimer with 0 or 1 frame of interval.

local function PostNewRoom()
    Isaac.CreateTimer(function ()
        Isaac.CreateTimer(function ()
            Isaac.Spawn(
                EntityType.ENTITY_PICKUP,
                PickupVariant.PICKUP_COLLECTIBLE,
                CollectibleType.COLLECTIBLE_SAD_ONION,
                Game():GetRoom():GetCenterPos(),
                Vector.Zero,
                nil
            )
        end, 30, 1, true)
    end, 0, 1, true)
end

theMonwil avatar May 21 '24 20:05 theMonwil

Seeing the timer in a timer is really cursed lol

Foks256 avatar May 21 '24 21:05 Foks256