Page 1 of 1
Transforming an NPC to another?
Posted: Sat May 22, 2021 4:50 pm
by LunarCatUSA
If I wanted an NPC, let’s say ID:1 (goomba), to be transformed to another NPC, let’s say ID: 4 (green koopa), what’s the code I would go about using? [I thought it was something among the lines of npc.transform() or something like that]
Re: Transforming an NPC to another?
Posted: Sat May 22, 2021 4:55 pm
by Emral
Re: Transforming an NPC to another?
Posted: Sat May 22, 2021 5:07 pm
by LunarCatUSA
Well I was right about the code,
So what, it’s like:
myNPC = NPC.get(1, player.section)
myNPC:transform(4)
Something like that?
Re: Transforming an NPC to another?
Posted: Sat May 22, 2021 5:59 pm
by Emral
LunarCatUSA wrote: ↑Sat May 22, 2021 5:07 pm
Well I was right about the code,
So what, it’s like:
myNPC = NPC.get(1, player.section)
myNPC:transform(4)
Something like that?
NPC.get returns a table of NPCs. You need to iterate over it to get to the individual npcs. It'd be like:
Code: Select all
for k,v in ipairs(NPC.get(1, player.section) do
v:transform(4)
end
Re: Transforming an NPC to another?
Posted: Sun May 23, 2021 11:42 pm
by LunarCatUSA
So now, how would I make the NPC’s speed 0? The NPC seems to be still in motion when it transforms, I intend for it to stop.
Re: Transforming an NPC to another?
Posted: Mon May 24, 2021 12:53 am
by Emral
LunarCatUSA wrote: ↑Sun May 23, 2021 11:42 pm
So now, how would I make the NPC’s speed 0? The NPC seems to be still in motion when it transforms, I intend for it to stop.
Setting
myNPC.speedX = 0 right below should work, unless the new npc is a walker type.
Re: Transforming an NPC to another?
Posted: Mon May 24, 2021 10:07 am
by LunarCatUSA
That’s not working, if I wanted to just despawn the npc by removing it via layers, how would I go about spawning a new npc at it’s position? When I type myNPC.x = posX and myNPC.y = posY, I get an error message saying “can’t convert nil to double”
Added in 6 minutes 51 seconds:
Oh nevermind, I found a way
Added in 25 seconds:
Just had to set the motion in line with the tick function, not immediately after the event.