Jump to content
tommysticks

Lua Table Question

Recommended Posts

I'm trying to alter player XP using a table with this code:

for i, k in pairs(Perks) do
  getPlayer():getXp():AddXP(Perks.k, 10);
end

...and it's not working. When I print Perks.k it comes up nil, but if I print k alone it prints as the userdata from the Perks table, Sprinting as an example. And to check to see if this is the same data as Perks.Sprinting I did a quick "if k == Perks.Sprinting" and it came out true.

 

Any insight on this would be appreciated. @RoboMat if you're still around I figure the issue is probably apparent to you.

Share this post


Link to post
Share on other sites

Use Perks.FromString (or Perks.fromIndex if you're iterating numerically). I don't know why, but accessing Perks like a regular table & passing it to a Kahlua function results in errors.

for i, k in pairs(Perks) do
    local perk = Perks.FromString(i)
    if PerkFactory.getPerk(perk) ~= nil then
        getPlayer():getXp():AddXP(perk,10)
    end
end

Some of the "perks" (i.e Agility) are categories, so I'd recommend using PerkFactory.getPerk to ensure that the perk exists.

Edited by ethanwdp

Share this post


Link to post
Share on other sites
18 hours ago, ethanwdp said:

<stuff>

Thanks again bro, I spent hours yesterday messin around with this. I have an aversion to asking for help on here, but I should have just done that right away. Would have saved me some time. This does exactly what I was lookin for.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...