Page 1 of 1

Linking functions to functions help

Posted: Sun Nov 06, 2022 12:21 am
by DRACalgar Law
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?

Re: Linking functions to functions help

Posted: Sun Nov 06, 2022 5:59 am
by deice
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

Re: Linking functions to functions help

Posted: Tue Nov 08, 2022 9:04 am
by Hoeloe
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.