Reputation: 3
I am trying to make my first mod for The Binding Of Isaac, but it says that the speed value is a nil value. As someone who doesn't know a lot about programming, why is it set to nil instead of the in-game value of 1? And how can I fix it?
local sodamod = RegisterMod("soda mod", 1)
local soda = Isaac.GetItemIdByName("Soda Bottle")
local speedgive = 0.5
function sodamod:EvaluateCache(player, cacheflags)
if cacheflags & CacheFlag.CACHE_SPEED == CacheFlag.CACHE_SPEED then
local itemcount = player:GetCollectibleNum(soda)
local addspeed = speedgive * itemcount
player.Speed = player.Speed + addspeed
end
end
sodamod:AddCallback(ModCallbacks.MC_EVALUATE_CACHE, sodamod.EvaluateCache)
I tried setting the speed value as a variable, but it still returned as an error.
Upvotes: 0
Views: 282
Reputation: 26355
Per this documentation, the EntityPlayer
movement speed stat is MoveSpeed
.
Try something like:
local sodamod = RegisterMod("soda mod", 1)
local soda = Isaac.GetItemIdByName("Soda Bottle")
local increase = 0.5
function sodamod:EvaluateCache(player, cacheflags)
if cacheflags & CacheFlag.CACHE_SPEED == CacheFlag.CACHE_SPEED then
local count = player:GetCollectibleNum(soda)
player.MoveSpeed = player.MoveSpeed + (count * increase)
end
end
sodamod:AddCallback(ModCallbacks.MC_EVALUATE_CACHE, sodamod.EvaluateCache)
Aside, from MC_EVALUATE_CACHE
:
Note that the value passed to the callback will always be an exact value of the CacheFlag enum. It is never a composition of two or more CacheFlags. Thus, you should always use normal equality instead of bitwise operators when comparing the cache flag.
AFAICT,
function sodamod:EvaluateCache(player, flag)
if flag == CacheFlag.CACHE_SPEED then
--- ...
is more appropriate.
Upvotes: 0