Page 1 of 1

Variable gets set to nil when it shouldn't

Posted: Fri May 24, 2024 7:13 am
by Jipjang
I'm making a Mario like platformer level editor and I'm currently working on customizable enemies and objects. But when an enemy transforms it should have the same movespeed that it had before. But for some reason, it gets set to nil.

Code: Select all


local transformedfrom = obj.transformedfrom
local koopa = OBJECTS:transform(i, obj, 16)
koopa.vx = 0
koopa.vy = 0
koopa.invincframes = 14
print(transformedfrom[2].mvspd) --prints 4
koopa.mvspd = transformedfrom[2].mvpsd --for some reason koopa.mvspd gets set to nil instead
if obj.x > PLAYER.x then
	koopa.facing = -1
else
	koopa.facing = 1
end
if obj == PLAYER.holding then
	PLAYER:die()
end
obj.type = "dead" --deletes the original object


Re: Variable gets set to nil when it shouldn't

Posted: Fri May 24, 2024 4:31 pm
by marclurr
Read this line really carefully.

Code: Select all

koopa.mvspd = transformedfrom[2].mvpsd

Re: Variable gets set to nil when it shouldn't

Posted: Fri May 24, 2024 6:02 pm
by Jipjang
marclurr wrote: Fri May 24, 2024 4:31 pm Read this line really carefully.

Code: Select all

koopa.mvspd = transformedfrom[2].mvpsd
Yeah I just noticed bruh

Re: Variable gets set to nil when it shouldn't

Posted: Fri May 24, 2024 6:22 pm
by dusoft
Jipjang wrote: Fri May 24, 2024 6:02 pm
marclurr wrote: Fri May 24, 2024 4:31 pm Read this line really carefully.

Code: Select all

koopa.mvspd = transformedfrom[2].mvpsd
Yeah I just noticed bruh
Maybe use editor that does some basic checking, bruh.

Also you forgot to say thanks, bruh.