Thread Tools Display Modes
01-22-16, 02:47 PM   #1
NeXxUSA
A Murloc Raider
Join Date: Jan 2016
Posts: 8
QuestFrames Help

Please check out this code. It is supposed to show the quest info in a movable frame, but it dosen't seem to be working. Any help/suggestions appreciated!

LINK

Last edited by NeXxUSA : 01-22-16 at 04:20 PM. Reason: Edit URL
  Reply With Quote
01-22-16, 05:12 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Aside from generic globals, passing your desired frame name as the first argument to CreateFrame, calling a function that doesn't exist (or you're not showing all of your code), setting a fontstring to literally display "i", making new frames every time these functions are called, and not actually calling these 2 functions (again, probably not showing all of your code), what exactly are you having trouble with?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-22-16, 05:15 PM   #3
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
There are a lot of errors in this code.

Lua Code:
  1. local i= GetQuestObjectInfo
This doesn't do anything, unless you created a global function called GetQuestObjectInfo. There is no such global function provided by Blizzard. Also, "i" is usually an abbreviation of "index", which is used in loops. You should not use that variable name in a case like this.

Lua Code:
  1. MyFrame = CreateFrame("Quest Info") -- globally defined variable name, incorrect arguments
  2. local MyFrame = CreateFrame("Frame", "QuestInfo", UIParent) -- localized, correct arguments
MyFrame is also not a good variable name and it should definitely not be globally defined. If you're going to keep using the same frame for multiple things, I suggest you create it in a higher scope and then refer to it directly in the functions.

Lua Code:
  1. MyFrame.text:SetAllPoints() -- no argument
  2. MyFrame.text:SetAllPoints(MyFrame) -- match the points of MyFrame
SetAllPoints takes a frame or region as an argument.

Lua Code:
  1. MyFrame.text:SetText("i")
This will only put the letter "i" in the text box.

Lua Code:
  1. MyFrame:SetMovable(enable) -- "enable" is nil, it doesn't exist
  2. MyFrame:SetMovable(true) -- true to enable, false to disable
enable isn't mentioned anywhere else in your code, so it will be nil in this case since it will be treated as a global variable (which, again, doesn't exist).

Lua Code:
  1. MyFrame = Frame("Quest Info") -- trying to grab the frame again?
  2. local MyFrame = QuestInfo --  get the frame from global namespace
Unless you made it yourself, there is no global function called "Frame".

Lua Code:
  1. MyFrame:Clear() -- attempting to clear text?
  2. MyFrame.text:SetText() -- this will clear the text field
If MyFrame is an arbitrary frame, then there is no function called "Clear" mixed in.

Lua Code:
  1. region = MyFrame:CreateTitleRegion() -- globally defined and pointless
  2. local region = MyFrame:CreateTitleRegion() -- localized, but this is still pointless

You can't just copy & paste from wowprogramming. If you look at the argument listing for any function, you'll see that each argument has a data type and each return value has a label to let you know what's being returned. "region" just tells you that the function is returning a region (which could be a Frame, FontString, Texture, Button, etc). "enable" just tells you what the arugment you give the function will do. If you give it true then it will enable. If you give it false, then it will disable.

This code will still do nothing (since I'm not entirely sure what you're trying to do), but it's correctly written:
Lua Code:
  1. local QuestInfo = CreateFrame("Frame", "QuestInfo", UIParent)
  2.  
  3. QuestInfo:SetHeight(300)
  4. QuestInfo:SetWidth(300)
  5. QuestInfo:SetPoint("CENTER", 0, 0)
  6. QuestInfo:SetBackdrop(StaticPopup1:GetBackdrop())
  7.  
  8. QuestInfo:EnableMouse(true)
  9. QuestInfo:SetMovable(true)
  10. QuestInfo:RegisterForDrag("LeftButton")
  11. QuestInfo:HookScript("OnDragStart", QuestInfo.StartMoving)
  12. QuestInfo:HookScript("OnDragStop", QuestInfo.StopMovingOrSizing)
  13.  
  14. QuestInfo.Text = QuestInfo:CreateFontString("$parentText", "BACKGROUND", "GameFontNormal")
  15. QuestInfo.Text:SetAllPoints(QuestInfo)
  16. QuestInfo.Text:SetText("This is your frame")
  17.  
  18. function QuestInfo:Accepted(...)
  19.     local arg1, arg2, arg3 = ...
  20.     self.Text:SetText(arg1 or arg2 or arg3)
  21. end
  22.  
  23. function QuestInfo:Complete(...)
  24.     local arg1, arg2, arg3 = ...
  25.     self.Text:SetText()
  26. end
__________________

Last edited by MunkDev : 01-22-16 at 05:21 PM.
  Reply With Quote
01-22-16, 06:03 PM   #4
NeXxUSA
A Murloc Raider
Join Date: Jan 2016
Posts: 8
Originally Posted by MunkDev View Post
There are a lot of errors in this code.

Lua Code:
  1. local i= GetQuestObjectInfo
This doesn't do anything, unless you created a global function called GetQuestObjectInfo. There is no such global function provided by Blizzard. Also, "i" is usually an abbreviation of "index", which is used in loops. You should not use that variable name in a case like this.

Lua Code:
  1. MyFrame = CreateFrame("Quest Info") -- globally defined variable name, incorrect arguments
  2. local MyFrame = CreateFrame("Frame", "QuestInfo", UIParent) -- localized, correct arguments
MyFrame is also not a good variable name and it should definitely not be globally defined. If you're going to keep using the same frame for multiple things, I suggest you create it in a higher scope and then refer to it directly in the functions.

Lua Code:
  1. MyFrame.text:SetAllPoints() -- no argument
  2. MyFrame.text:SetAllPoints(MyFrame) -- match the points of MyFrame
SetAllPoints takes a frame or region as an argument.

Lua Code:
  1. MyFrame.text:SetText("i")
This will only put the letter "i" in the text box.

Lua Code:
  1. MyFrame:SetMovable(enable) -- "enable" is nil, it doesn't exist
  2. MyFrame:SetMovable(true) -- true to enable, false to disable
enable isn't mentioned anywhere else in your code, so it will be nil in this case since it will be treated as a global variable (which, again, doesn't exist).

Lua Code:
  1. MyFrame = Frame("Quest Info") -- trying to grab the frame again?
  2. local MyFrame = QuestInfo --  get the frame from global namespace
Unless you made it yourself, there is no global function called "Frame".

Lua Code:
  1. MyFrame:Clear() -- attempting to clear text?
  2. MyFrame.text:SetText() -- this will clear the text field
If MyFrame is an arbitrary frame, then there is no function called "Clear" mixed in.

Lua Code:
  1. region = MyFrame:CreateTitleRegion() -- globally defined and pointless
  2. local region = MyFrame:CreateTitleRegion() -- localized, but this is still pointless

You can't just copy & paste from wowprogramming. If you look at the argument listing for any function, you'll see that each argument has a data type and each return value has a label to let you know what's being returned. "region" just tells you that the function is returning a region (which could be a Frame, FontString, Texture, Button, etc). "enable" just tells you what the arugment you give the function will do. If you give it true then it will enable. If you give it false, then it will disable.

This code will still do nothing (since I'm not entirely sure what you're trying to do), but it's correctly written:
Lua Code:
  1. local QuestInfo = CreateFrame("Frame", "QuestInfo", UIParent)
  2.  
  3. QuestInfo:SetHeight(300)
  4. QuestInfo:SetWidth(300)
  5. QuestInfo:SetPoint("CENTER", 0, 0)
  6. QuestInfo:SetBackdrop(StaticPopup1:GetBackdrop())
  7.  
  8. QuestInfo:EnableMouse(true)
  9. QuestInfo:SetMovable(true)
  10. QuestInfo:RegisterForDrag("LeftButton")
  11. QuestInfo:HookScript("OnDragStart", QuestInfo.StartMoving)
  12. QuestInfo:HookScript("OnDragStop", QuestInfo.StopMovingOrSizing)
  13.  
  14. QuestInfo.Text = QuestInfo:CreateFontString("$parentText", "BACKGROUND", "GameFontNormal")
  15. QuestInfo.Text:SetAllPoints(QuestInfo)
  16. QuestInfo.Text:SetText("This is your frame")
  17.  
  18. function QuestInfo:Accepted(...)
  19.     local arg1, arg2, arg3 = ...
  20.     self.Text:SetText(arg1 or arg2 or arg3)
  21. end
  22.  
  23. function QuestInfo:Complete(...)
  24.     local arg1, arg2, arg3 = ...
  25.     self.Text:SetText()
  26. end
Originally Posted by Seerah View Post
Aside from generic globals, passing your desired frame name as the first argument to CreateFrame, calling a function that doesn't exist (or you're not showing all of your code), setting a fontstring to literally display "i", making new frames every time these functions are called, and not actually calling these 2 functions (again, probably not showing all of your code), what exactly are you having trouble with?
Thanks for the response guys! I don't know lua(JS, C, C#, JQ, HTML guy myself) or the WoW API at all really. Could you guys point me in the direction of some tutorials(preferably videos) to help me get on my way? Thanks again for the detail in your responses! As far as the copy and paste thing, when I first started learning javascript I would compile various pieces of code a tweak and mash them together to my liking, and learn from what I see. Obviously the semi-self-taught route isn't going to work for Lua.
  Reply With Quote
01-22-16, 06:06 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by MunkDev View Post
"i" is usually an abbreviation of "index"
Actually, the use of the variable i in loops is based off usage in mathematical formulas. In both cases, they represent a set of numbers used in iteration. By "they", there are actually a series of them usually represented by i, j, and k. There can be more if necessary and continue along the alphabet.



Originally Posted by NeXxUSA View Post
I don't know lua(JS, C, C#, JQ, HTML guy myself) or the WoW API at all really.
...
As far as the copy and paste thing, when I first started learning javascript I would compile various pieces of code a tweak and mash them together to my liking, and learn from what I see. Obviously the semi-self-taught route isn't going to work for Lua.
I'm actually self taught myself. Granted I've had Lua experience prior to when I first started writing addons. Before Lua, I've had experience with other languages such as JavaScript, C, PHP, etc. Once you get a taste of a variety of languages, you begin to see the similarities they all share. They all have variables, conditions, loops, and functions. They also have their own quirks that make them unique. Such as how strictly variables are typed, passing objects by reference or by value, even Lua's quirk with allowing functions to have multiple returns.

I know it isn't exactly what you asked for, but I would suggest taking a look at the Lua Reference Manual and the WoWPedia Tutorial.



As always, if you have any questions, feel free to ask.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 01-22-16 at 06:24 PM.
  Reply With Quote
01-22-16, 08:19 PM   #6
NeXxUSA
A Murloc Raider
Join Date: Jan 2016
Posts: 8
Originally Posted by SDPhantom View Post
Actually, the use of the variable i in loops is based off usage in mathematical formulas. In both cases, they represent a set of numbers used in iteration. By "they", there are actually a series of them usually represented by i, j, and k. There can be more if necessary and continue along the alphabet.




I'm actually self taught myself. Granted I've had Lua experience prior to when I first started writing addons. Before Lua, I've had experience with other languages such as JavaScript, C, PHP, etc. Once you get a taste of a variety of languages, you begin to see the similarities they all share. They all have variables, conditions, loops, and functions. They also have their own quirks that make them unique. Such as how strictly variables are typed, passing objects by reference or by value, even Lua's quirk with allowing functions to have multiple returns.

I know it isn't exactly what you asked for, but I would suggest taking a look at the Lua Reference Manual and the WoWPedia Tutorial.



As always, if you have any questions, feel free to ask.
Thanks! Any help is good help!
  Reply With Quote
01-22-16, 08:36 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
To add to what SDPhantom said, using i (or j, or k) in those scenarios is just convention - those variables can be called whatever you like.

@MunkDev: the SetAllPoints method does not require an argument. If nil, it will default to the parent frame.

@NeXxUSA: I am self-taught as well. I'm a music (primarily) teacher. See here for more resources: http://www.wowinterface.com/forums/s...ad.php?t=43699
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-24-16, 07:34 PM   #8
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
I'm not unfamiliar with practices when it comes to iteration variables, but I always thought the reason i was picked (and subsequently j and k) as an iteration variable, was because it's usually used to get a specific index in an array. I'm damaged from writing in C languages, so even when I do arbitrary examples of table iteration in Lua, I usually use i instead of k (key). Oh well, you learn something new everyday.

As for being self-taught; I didn't know a thing about Lua or addon coding about a year ago. Barely even looking at some of my old coding gives me a headache because of how inexperienced I was, and I'm sure I'm likely to feel the same about my current coding, somewhere down the road. I hope you didn't perceive my answer as harsh, I was merely trying to help. Things might be unclear right now, but if you keep at it, you'll get a grip of it all in no time.
__________________
  Reply With Quote
01-24-16, 09:54 PM   #9
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
And that may well be how i became the conventional/traditional variable to use in that context. However, this also works quite as well.

Lua Code:
  1. for mycoolvar = 1, 3 do
  2.      print(mycoolvar)
  3. end
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-24-16, 10:11 PM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I was just pointing out some trivia behind programming conventions. In the early days of computers, they were solely used for mathematical calculations. The formulas used for such literally was the program code these computers ran. It's these roots that many of our programming conventions originated from.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » QuestFrames Help


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