TeamREPENTOGON / REPENTOGON

Script extender for The Binding of Isaac: Repentance
https://repentogon.com/
GNU General Public License v2.0
107 stars 11 forks source link

Isaac.CreateTimer runs instantly in MC_POST_NEW_ROOM #462

Open theMonwil opened 1 month ago

theMonwil commented 1 month ago

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
Foks256 commented 1 month ago

Seeing the timer in a timer is really cursed lol