Thread Tools Display Modes
11-20-13, 09:48 AM   #1
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
needing some help here

its quite simple in concept but i cant get it to work, i know im messing up here somewhere

if anyone can help,
the intended result is to give an aspect ratio of your screen

local resMath1 = GetScreenHeight()
local resMath2 = GetScreenWidth()
local resMathVar = (resMath2()\resMath1())
print ("Your Current Ratio is", resMathVar)
  Reply With Quote
11-20-13, 10:02 AM   #2
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
nevermind i feelk stupid, i rewrote it a different way and realized my mistake

local sheight = GetScreenHeight()
local swidth = GetScreenWidth()
local resMathVar = (swidth/sheight)
print ("Your Current Ratio is", resMathVar)

herpderp
  Reply With Quote
11-20-13, 10:48 AM   #3
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Glad you were able to figure it out yourself, but just so you know what you did wrong:

Code:
local resMath1 = GetScreenHeight()
local resMath2 = GetScreenWidth()
local resMathVar = (resMath2()resMath2\/resMath1()resMath1)
print ("Your Current Ratio is", resMathVar)

Your original code, in red, is attempting to call a function, denoted by the (), when in reality, you just need to reference your variable which already has the appropriate information stored in it.

Last edited by Clamsoda : 11-20-13 at 12:41 PM.
  Reply With Quote
11-20-13, 11:07 AM   #4
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
And \ is a back slash, not a division operator.
  Reply With Quote
11-20-13, 11:13 AM   #5
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by Rainrider View Post
And \ is a back slash, not a division operator.
originally that was my problem, i added in the ( ) trying to get it to work.... damn typos, \ instead of /


this little tidbit is the backbone of my whole addon my local resMathVar will tell the program what set of presets to use to line up everything without input from the user, and if it falls out of parameters of what i have programmed for settings, ill pop up a window saying this addon not yet compatible with your screen resolution

Last edited by Uitat : 11-20-13 at 11:16 AM. Reason: jsut a note
  Reply With Quote
11-20-13, 11:26 AM   #6
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
You'd better post the code that produced the error, not you're subsequent tries to fix it. This way you may get your answer faster.

Apart from that be more mnemonic about your variables. What the hell is resMathVar? I bet you won't be able to tell that in a month or two without looking at the calculations done. Just call it aspectRatio or something.
  Reply With Quote
11-20-13, 12:39 PM   #7
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by Rainrider View Post
You'd better post the code that produced the error, not you're subsequent tries to fix it. This way you may get your answer faster.

Apart from that be more mnemonic about your variables. What the hell is resMathVar? I bet you won't be able to tell that in a month or two without looking at the calculations done. Just call it aspectRatio or something.
Resolution Math for Variable
  Reply With Quote
11-20-13, 12:46 PM   #8
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
besides i already use aspectRatio in another part of the addon to call up the settings that will apply for me the resMathVar

i give very clean Descriptions of what is in each Portion of the addon in green block commenting

such as this

---------------------------------------------------------
-- First Lets Find Your Resolution Ratio and set it to a
-- variable and assign it to the Variable ResMathVar
---------------------------------------------------------

local resMath1 = GetScreenHeight()
local resMath2 = GetScreenWidth()
local resSetting = (resMath2/resMath1)
print ("Your Current Ratio is", resSetting)
  Reply With Quote
11-20-13, 04:12 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'd have to say that "screenHeight" and "screenWidth" would be infinitely better variable names than "resMathVar1" and "resMathVar2" but if you're used to some language/framework with horrible variable naming conventions, I guess you can use those latter ones...

Also, in the example you posted, your comment is inaccurate... there isn't a variable named "resMathVar" at all, and neither of the similarly-named variables contain the calculated "resolution ratio" (I think you meant "aspect ratio"; I've never heard it called "resolution ratio" in any context).
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-20-13, 04:41 PM   #10
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
No point in even assigning them to variables if they're only being used once, might as well do print('Aspect ratio:', GetScreenWidth() / GetScreenHeight()).
  Reply With Quote
11-21-13, 03:56 AM   #11
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by semlar View Post
No point in even assigning them to variables if they're only being used once, might as well do print('Aspect ratio:', GetScreenWidth() / GetScreenHeight()).
actually i understand where you are going here, but through the entire addon i reference the screen size or ratio to set size and appropriate positioning, by doing this i can make it a drop and go no setup needed no WTF file needed single folder addon, at least this is the goal, alternitavely, i have a config program to alter the positioning if 100% needed
  Reply With Quote
11-21-13, 04:14 AM   #12
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
ok so i took advice and did find/replace on 20 lua files to accommodate the changes i am posting here, i do value your suggestions and this time after thinking about it and tossing out the pride here are my changes

tell me what you think.

local resolHeight = GetScreenHeight()
local resolWidth = GetScreenWidth()
local aspectRatio = (resolWidth/resolHeight)
-- print out to chat to confirm aspect ratio has value this is tempoaray, not intended for end user
print ("if this function works your Aspect ratio is", aspectRatio)


is there a way in lua for me to reduce the value ofr aspectRatio to 2 decimals rather then having 1.77777777bla bla bla
  Reply With Quote
11-21-13, 06:42 AM   #13
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Use the float parameter of format.

Lua Code:
  1. local truncatedDecimal = format("%.2f", 3.14159265359)
  Reply With Quote
11-21-13, 07:00 AM   #14
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by Clamsoda View Post
Use the float parameter of format.

Lua Code:
  1. local truncatedDecimal = format("%.2f", 3.14159265359)
so in turn my code should look something like this correct?

Lua Code:
  1. local resolHeight = GetScreenHeight()
  2. local resolWidth = GetScreenWidth()
  3. local aspectRatio = (resolWidth/resolHeight)
  4. print ("if this function works your Aspect ratio is", format("%.2f", aspectRatio))
  Reply With Quote
11-21-13, 07:13 AM   #15
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
I don't see why that wouldn't work, but I'd rather use this approach:

Code:
print(format("If this function works, your aspect ratio is %.2f.", aspectRatio))
By keeping everything you want to print inside of the first argument of format, you have finer control of what is printed, and how. I have highlighted the pattern that the Lua interpreter will recognize, as well as the variable that will be inserted where that pattern is, to ease the understanding.

The format function, and the patterns it recognizes are FAR from intuitive. I highly suggest reading further into the topic on WoWPedia and in official Lua documentation.

Last edited by Clamsoda : 11-21-13 at 07:18 AM.
  Reply With Quote
11-21-13, 07:16 AM   #16
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
so far so good

this is just the artwork , still not ready to post the code for the bars, just want your guys opinion if it flows well and the naming conventions are good

Lua Code:
  1. local aspect = CreateFrame("Frame", nil, UIParent)
  2.         aspect:RegisterEvent("PLAYER_ENTERING_WORLD")
  3.         aspect:SetScript("OnEvent", function(self, event)
  4.             UIParent:SetScale(0.6)  -- you can change the scale here but you will break the entire add-on --
  5.             aspect:UnregisterAllEvents()
  6.         print ("Your Resolution Scale has been changed to 0.6")
  7. end)
  8.  
  9.  
  10. -- welcome to Project Deranjata Artwork, Visual Style Portion of Project Deranjata
  11.  
  12. local resolHeight = GetScreenHeight()
  13. local resolWidth = GetScreenWidth()
  14. local aspectRatio = (resolWidth/resolHeight)
  15. print ("if this function works your Aspect ratio is", format("%.2f", aspectRatio))
  16.  
  17. --This is the Backdrop Variable--
  18. local backdrop = {
  19.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  20.     edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
  21.     tile = true,
  22.     tileSize = 32,
  23.     edgeSize = 20,
  24.     insets = {
  25.         left = 4,
  26.         right = 4,
  27.         top = 4,
  28.         bottom = 4,
  29.         }
  30.     }
  31. -- This is Left Main Frame Chunk
  32. local frame = CreateFrame("frame", "LeftChatBaseFrame", UIParent)
  33.         LeftChatBaseFrame:SetWidth(resolWidth*.34)
  34.         LeftChatBaseFrame:SetHeight(resolHeight*.33)
  35.         LeftChatBaseFrame:SetPoint("BOTTOMLEFT", UIParent,"BOTTOMLEFT", -6, -6)
  36.         LeftChatBaseFrame:SetFrameStrata("BACKGROUND")
  37.         LeftChatBaseFrame:SetFrameLevel(1) 
  38.         LeftChatBaseFrame:SetAlpha(1)
  39.         LeftChatBaseFrame:SetBackdrop(backdrop)
  40. -- This is Right Main Frame Chunk
  41. local frame = CreateFrame("frame", "RightChatBaseFrame", UIParent)
  42.         RightChatBaseFrame:SetWidth(resolWidth*.34)
  43.         RightChatBaseFrame:SetHeight(resolHeight*.33)
  44.         RightChatBaseFrame:SetPoint("BOTTOMRIGHT", UIParent,"BOTTOMRIGHT", 6, -6)
  45.         RightChatBaseFrame:SetFrameStrata("BACKGROUND")
  46.         RightChatBaseFrame:SetFrameLevel(1)
  47.         RightChatBaseFrame:SetAlpha(1)
  48.         RightChatBaseFrame:SetBackdrop(backdrop)
  49. -- This is the Center Main Frame Chunk
  50. local frame = CreateFrame("frame", "CenterBase", UIParent)
  51.         CenterBase:SetWidth(resolWidth*1.007)
  52.         CenterBase:SetHeight(resolHeight*.21)
  53.         CenterBase:SetPoint("BOTTOM", UIParent,"BOTTOM", 0, -6)
  54.         CenterBase:SetFrameStrata("BACKGROUND")
  55.         CenterBase:SetFrameLevel(2)
  56.         CenterBase:SetBackdrop(backdrop)
  57. -- This is map frame chunk 
  58. local frame = CreateFrame("frame", "CenterMapBase", UIParent)
  59.         CenterMapBase:SetWidth(resolHeight*.21)
  60.         CenterMapBase:SetHeight(resolHeight*.21)
  61.         CenterMapBase:SetPoint("BOTTOM", UIParent,"BOTTOM", 0, -6)
  62.         CenterMapBase:SetFrameStrata("BACKGROUND")
  63.         CenterMapBase:SetFrameLevel(3)
  64.         CenterMapBase:SetBackdrop(backdrop)
  65.        
  66. --Button False Embed--
  67. local frame = CreateFrame("Button", "ExpandLeft", LeftChatBaseFrame, "UIPanelButtonTemplate")
  68. frame:SetHeight(21)
  69. frame:SetWidth(21)
  70. frame:SetText("R")
  71. frame:ClearAllPoints()
  72. frame:SetPoint("TOPRIGHT", -4, -4)
  73. ExpandLeft:SetScript("OnClick", ReloadUI)
  74.  
  75. --Button False Embed--
  76. local frame = CreateFrame("Button", "ExpandRight", RightChatBaseFrame, "UIPanelButtonTemplate")
  77. frame:SetHeight(21)
  78. frame:SetWidth(22)
  79. frame:SetText("B")
  80. frame:ClearAllPoints()
  81. frame:SetPoint("BOTTOMRIGHT", -4, 4)
  82. ExpandRight:SetScript("OnClick", ToggleAllBags)

Last edited by Uitat : 11-21-13 at 07:21 AM. Reason: forgot the aspect ratio changing fuction
  Reply With Quote
11-21-13, 07:23 AM   #17
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
this is the end result of the code, please disregard bars as i am not ready to publish that code, its very messy
Attached Thumbnails
Click image for larger version

Name:	WoWScrnShot_112113_081011.jpg
Views:	408
Size:	463.8 KB
ID:	7947  
  Reply With Quote
11-21-13, 10:16 AM   #18
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,237
If I understand correctly, you are creating an user interface that will work on any resolution, correct? In that case, you need to also factor in GetEffectiveScale() ... Which Phanx pointed out in some of my code.

The reason you need to know the UI scale is because while I use the lowest UI scale, Frank uses the highest, and Sally uses something in the middle.
  Reply With Quote
11-21-13, 10:32 AM   #19
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by myrroddin View Post
If I understand correctly, you are creating an user interface that will work on any resolution, correct? In that case, you need to also factor in GetEffectiveScale() ... Which Phanx pointed out in some of my code.

The reason you need to know the UI scale is because while I use the lowest UI scale, Frank uses the highest, and Sally uses something in the middle.
at this time, i am scaling their screen for them.

in this case...
Lua Code:
  1. local aspect = CreateFrame("Frame", nil, UIParent)
  2.         aspect:RegisterEvent("PLAYER_ENTERING_WORLD")
  3.         aspect:SetScript("OnEvent", function(self, event)
  4.             UIParent:SetScale(0.6)  -- you can change the scale here but you will break the entire add-on --
  5.             aspect:UnregisterAllEvents()
  6.         print ("Your Resolution Scale has been changed to 0.6")
  7. end)

i notify them that i have changed their scale.

it is set by hard code to 0.6, in the future i may change this, but for now, i think i may hold steady on this... from what i can tell, the pixle ratio is very clear at .6, where as in other scales near that, they seem to distort the graphics
  Reply With Quote
11-24-13, 06:14 AM   #20
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Originally Posted by Uitat View Post
Lua Code:
  1. local aspect = CreateFrame("Frame", nil, UIParent)
  2.         aspect:RegisterEvent("PLAYER_ENTERING_WORLD")
  3.         aspect:SetScript("OnEvent", function(self, event)
  4.             UIParent:SetScale(0.6)  -- you can change the scale here but you will break the entire add-on --
  5.             aspect:UnregisterAllEvents()
  6.         print ("Your Resolution Scale has been changed to 0.6")
  7. end)

The indentation you're using there is a bit confusing. Disregard this if that's due to pasting it onto a forum. I'd indent it like this:
Lua Code:
  1. local aspect = CreateFrame("Frame", nil, UIParent)
  2. aspect:RegisterEvent("PLAYER_ENTERING_WORLD")
  3. aspect:SetScript(
  4.     "OnEvent",
  5.     function(self, event)
  6.         UIParent:SetScale(0.6)
  7.         self:UnregisterAllEvents()
  8.         print ("Your Resolution Scale has been changed to 0.6")
  9.     end
  10. )


I realize that my method of indenting complex function arguments is not everyone's cup of tea, though; so, alternatively:
Lua Code:
  1. local aspect = CreateFrame("Frame", nil, UIParent)
  2. aspect:RegisterEvent("PLAYER_ENTERING_WORLD")
  3. aspect:SetScript("OnEvent", function(self, event)
  4.         UIParent:SetScale(0.6)  -- you can change the scale here but you will break the entire add-on --
  5.         self:UnregisterAllEvents()
  6.         print ("Your Resolution Scale has been changed to 0.6")
  7. end)


Also, I changed aspect to self; I didn't see a reason to close on the aspect variable in that anonymous function when the frame reference is being passed into the function already.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » needing some help here

Thread Tools
Display Modes

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