Page 1 of 1

Can SaveData replace pnpc?

Posted: Sun Sep 04, 2022 2:03 am
by Wooliestplate89
I want to save a variable to a goomba npc but pnpc is deprecated, I think I can use SaveData to do this instead, but I'm not sure how to do it.

Here is my code:

Code: Select all

local goombajumpTimer = 0

function onTick()
    goombajumpTimer = goombajumpTimer + 1
    if goombajumpTimer > 80 then
        goombajumpTimer = 0
    end
    local goombas = NPC.get(1, player.section)
    for index,npc in ipairs(goombas) do
        if goombajumpTimer == 0 then
            npc.speedY = -10
        end
    end
end

Yes I am following Enjl's Luna Lua tutorial because I'm new to Luna lua,

Re: Can SaveData replace pnpc?

Posted: Sun Sep 04, 2022 2:26 am
by Emral
SaveData is for persistent storage across runs. pnpc is replaced by the data table.
https://www.youtube.com/watch?v=A3qBcwecmXk

for example you can have a npc.data.goombaJumpTimer and do the logic for the variable within the for loop

Re: Can SaveData replace pnpc?

Posted: Sun Sep 04, 2022 3:15 am
by Wooliestplate89
I just found out on the pge wiki that you can now access npc.data, npc.uid, npc.pid, and npc.pidIsDirty without pnpc, which is why pnpc is deprecated. I understand now.

Re: Can SaveData replace pnpc?

Posted: Sun Sep 04, 2022 3:19 am
by Emral
Wooliestplate89 wrote:
Sun Sep 04, 2022 3:15 am
I just found out on the pge wiki that you can now access npc.data, npc.uid, npc.pid, and npc.pidIsDirty without pnpc, which is why pnpc is deprecated. I understand now.
PGE wiki hasn't been maintained in a long time. SMBX2 documentation contains more information.
https://docs.codehaus.moe/#/concepts/data-table

Re: Can SaveData replace pnpc?

Posted: Sun Sep 04, 2022 9:14 am
by Wooliestplate89
Oooh thanks for telling me :D.