• Print

Author Topic: Add type()s  (Read 5047 times)

0 Members and 1 Guest are viewing this topic.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Add type()s
« on: June 09, 2017, 09:52:36 am »
I'm writing an addon that tracks experience to give things like rewards, levels, things like that. In this addon, I need a function that discerns between two different integers, and to check if it's a "Level" or an "Experience" (sounds weird, but follow along with me). In my function:
Code: Lua
  1.  
  2. function self:CheckForPrestige( current, change, take )
  3.     if not self:GetPrestige() > 0 then return end
  4.     if take then change = -change end
  5.     local target = current + change
  6.     local prestige = math.floor( ASET.PrestigeAtLevel( ASET.LevelAtExp( target ) ) )
  7.     if target < current then
  8.         if prestige < self:GetPrestige() then
  9.             return true, prestige
  10.         end
  11.     elseif target > current then
  12.         if prestige > self:GetPrestige() then
  13.             return true, prestige
  14.         end
  15.     else
  16.         return false, 0
  17.     end
  18. end
  19.  

this checks if a person is eligible to prestige, and if they are, return true and the prestige they are allowed up to (the second value is simply if their level or experience was set by an admin, otherwise their prestige would only increase by 1). Everything in this works regardless of if it's level or experience provided, except for this line:
Code: Lua
  1. local prestige = math.floor( ASET.PrestigeAtLevel( ASET.LevelAtExp( target ) ) )



This line checks the level at a given experience, because I originally wrote this function for checking prestiges when given experience, but now I need to check both because I added a "GiveLevel" function, as well.


So my question is, how can I modify the type function to be able to return the previously mentioned values? If that's not possible, how would I go about writing a separate function to do this?
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Add type()s
« Reply #1 on: June 09, 2017, 04:47:56 pm »
Type doesn't return variables. Type only tells you what type of data the variable is, a string, number, or a table.
If you pass it a integer in both experience or prestige, it's going to tell you its an integer. That's it.
I'm having trouble discerning the information you are wanting.
If you're wanting to determine what an integer is (Experience level or Prestige level), the easiest way (IMO) would be to use two different integer ranges.
Say, Both experience and prestige are levels 0-10.
Then in your functions, Experience could be 0-10. Prestige could be 100-110.
When wanting to check which is which in a single function, (if x-100 =>0) then it's Prestige.
All your functions related to setting prestige could easily add/subtract 100 if you wanted to keep input for end users easy/to the 1-10 range for both.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Add type()s
« Reply #2 on: June 09, 2017, 04:50:50 pm »
Ah, that makes a lot of sense actually. So set some arbitrary values that I can check. Thanks for the help, I was thinking of some way more complicated stuff lol
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print