Linking functions to functions help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
DRACalgar Law
Hoopster
Hoopster
Posts: 117
Joined: Sun Oct 16, 2022 3:59 pm
Flair: King of the Boss Makers
Pronouns: he/him
Contact:

Linking functions to functions help

Postby DRACalgar Law » Sun Nov 06, 2022 12:21 am

I tried putting a condition of

Code: Select all

if killReason == HARM_TYPE_JUMP and "variable from onTickNPC" then
in function onNPCHarm and didn't work. Is there a way to connect a function to function like connecting function onTickNPC to onNPCHarm for their variables?

deice
Volcano Lotus
Volcano Lotus
Posts: 541
Joined: Fri Jul 23, 2021 7:35 am

Re: Linking functions to functions help

Postby deice » Sun Nov 06, 2022 5:59 am

you should try putting the variable outside any one function's scope:

Code: Select all

local gvar = ...

function onTickNPC(v)
    gvar = ...
end

function onNPCHarm(token, killedNPC, killReason)
    if (killReason == HARM_TYPE_JUMP and gvar == ...) then
        ...
    end
end

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Linking functions to functions help

Postby Hoeloe » Tue Nov 08, 2022 9:04 am

It sounds more likely that you want to use the NPC's data table, rather than a script-wide variable. Script-wide variables only store one value, so it will be the same across all NPCs. However, NPC data tables (accessed via myNPC.data.myVar) allow you to store values for each NPC, which seems more likely to be what you want.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari