Thread Tools Display Modes
04-23-15, 10:57 AM   #1
tobias1919
A Deviate Faerie Dragon
Join Date: Mar 2015
Posts: 13
String ("number") into value (number)

Hello... I have an issue when extracting random_roll_result for a loot master addon i'm trying to write...
My issue with this is, that ":match()" returns strings... (Roll does not return as a value (88) but a string ("88") which makes comparing .... impossible? i don't know... But if anyone got a solution, i'd be happy

Lua Code:
  1. local highestRoll = 0
  2. local name, roll, minRoll, maxRoll = arg1:match("^(.+) rolls (%d+) %((%d+)%-(%d+)%)$") -- "Oijjoijj", "88", "1", "100"
  3. if roll >= highestRoll then  -- if "88" >= 0 then
  4.     if roll ~= highestRoll then
  5.         table.wipe(highestRoller)
  6.         highestRoll = roll
  7.     end
  8.     table.insert(highestRoller, 1, nameServer)
  9. end

EDIT: Found solution... tonumber...
Lua Code:
  1. local highestRoll = 0
  2. local name, roll, minRoll, maxRoll = arg1:match("^(.+) rolls (%d+) %((%d+)%-(%d+)%)$") -- "Oijjoijj", "88", "1", "100"
  3. local rollNum = tonumber(roll)
  4. if rollNum >= highestRoll then  -- if 88 >= 0 then
  5.     if roll ~= highestRoll then
  6.         table.wipe(highestRoller)
  7.         highestRoll = roll
  8.     end
  9.     table.insert(highestRoller, 1, nameServer)
  10. end

Last edited by tobias1919 : 04-23-15 at 11:11 AM.
  Reply With Quote
04-23-15, 02:24 PM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Use Lua's tonumber() function.

EDIT: Missed your "EDIT" because it was sandwiched between code blocks...
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
04-23-15, 11:37 PM   #3
tobias1919
A Deviate Faerie Dragon
Join Date: Mar 2015
Posts: 13
Sorry for the sandwiching - and thanks for reply!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » String ("number") into value (number)


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off