Thread Tools Display Modes
05-25-14, 09:28 AM   #1
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Set Script function

ok so im bout to go batty,
im trying to figure out how to incorperate this in to my addon

/script ChatFrame1:SetPoint("BOTTOMLEFT","LeftChatBaseFrame","BOTTOMLEFT", 0 ,0);
--x,y coordinants to docked frame (BottomLeft Corner, Main Chat)
/script ChatFrame1:SetPoint("TOPRIGHT","LeftChatBaseFrame","BOTTOMLEFT",451 ,241);
--x,y coordinants to docked frame (TopRight Corner, Main Chat)
/script ChatFrame2:SetPoint("BOTTOMLEFT","RightChatBaseFrame","BOTTOMLEFT", 8 ,0);
--x,y coordinants to docked frame (BottomLeft Corner, Combat Window)
/script ChatFrame2:SetPoint("TOPRIGHT","RightChatBaseFrame","BOTTOMLEFT",455 ,194);
--x,y coordinants to docked frame (TopRight Corner, Combat Window)


im trying to make a event handled function for rolling these scripts, but darn i really do not want to have an entire page devoted to this, lol

im thinking on player enters world run script above, i do not want to use XML and i know there is a way to lua it out but for the life of me i cant remember it
  Reply With Quote
05-25-14, 09:43 AM   #2
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
Code:
local DummyFrame = CreateFrame("Frame")
DummyFrame:SetScript("OnEvent", function(self, event, ...)
   if (event == "PLAYER_ENTERING_WORLD") then
      ChatFrame1:SetPoint("BOTTOMLEFT", LeftChatBaseFrame, "BOTTOMLEFT", 0, 0)
      ChatFrame1:SetPoint("TOPRIGHT", LeftChatBaseFrame, "BOTTOMLEFT", 451, 241)
      ChatFrame2:SetPoint("BOTTOMLEFT", RightChatBaseFrame, "BOTTOMLEFT", 8, 0)
      ChatFrame2:SetPoint("TOPRIGHT", RightChatBaseFrame, "BOTTOMLEFT", 455, 194)
   end
end)
Of course for this to work you're going to need a valid parent named LeftChatBaseFrame and RightChatBaseFrame. You may need/want to clear all points for both chat frames as well. ChatFrame1:ClearAllPoints() ChatFrame2:ClearAllPoints() and those would need to be placed before the setpoints.

http://wowpedia.org/API_Frame_SetScript
__________________
AddOns: Tim @ WoWInterface
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote
05-25-14, 09:59 AM   #3
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by Tim View Post
Code:
local DummyFrame = CreateFrame("Frame")
DummyFrame:SetScript("OnEvent", function(self, event, ...)
   if (event == "PLAYER_ENTERING_WORLD") then
      ChatFrame1:SetPoint("BOTTOMLEFT", LeftChatBaseFrame, "BOTTOMLEFT", 0, 0)
      ChatFrame1:SetPoint("TOPRIGHT", LeftChatBaseFrame, "BOTTOMLEFT", 451, 241)
      ChatFrame2:SetPoint("BOTTOMLEFT", RightChatBaseFrame, "BOTTOMLEFT", 8, 0)
      ChatFrame2:SetPoint("TOPRIGHT", RightChatBaseFrame, "BOTTOMLEFT", 455, 194)
   end
end)
Of course for this to work you're going to need a valid parent named LeftChatBaseFrame and RightChatBaseFrame. You may need/want to clear all points for both chat frames as well. ChatFrame1:ClearAllPoints() ChatFrame2:ClearAllPoints() and those would need to be placed before the setpoints.

http://wowpedia.org/API_Frame_SetScript
thank you man for the imput, im going to chk this out and see if this is exactly what i am looking for, my code was already 58 lines long and growing
  Reply With Quote
05-25-14, 10:23 AM   #4
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by Tim View Post
Code:
local DummyFrame = CreateFrame("Frame")
Originally Posted by Tim View Post
Code:
DummyFrame:SetScript("OnEvent", function(self, event, ...)
   if (event == "PLAYER_ENTERING_WORLD") then
      ChatFrame1:SetPoint("BOTTOMLEFT", LeftChatBaseFrame, "BOTTOMLEFT", 0, 0)
      ChatFrame1:SetPoint("TOPRIGHT", LeftChatBaseFrame, "BOTTOMLEFT", 451, 241)
      ChatFrame2:SetPoint("BOTTOMLEFT", RightChatBaseFrame, "BOTTOMLEFT", 8, 0)
      ChatFrame2:SetPoint("TOPRIGHT", RightChatBaseFrame, "BOTTOMLEFT", 455, 194)
   end
end)
Of course for this to work you're going to need a valid parent named LeftChatBaseFrame and RightChatBaseFrame. You may need/want to clear all points for both chat frames as well. ChatFrame1:ClearAllPoints() ChatFrame2:ClearAllPoints() and those would need to be placed before the setpoints.

http://wowpedia.org/API_Frame_SetScript
ok here it is with the top portion of my code no longer referancing to the file that i was working on, i just dumped it in after my chat frame creation

Code:
-- welcome to Project Deranjata Artwork, Visual Style Portion of Project Deranjata

local aspect = CreateFrame("Frame", nil, UIParent)
aspect:RegisterEvent("PLAYER_ENTERING_WORLD")
aspect:SetScript("OnEvent", function(self, event)
    UIParent:SetScale(0.6)    -- you can change the scale here but you will break the entire add-on --
    aspect:UnregisterAllEvents()
    print ("Your Resolution Scale has been changed to 0.6")
    print ("Welcome to Project Deranjata, Version 0.0.1.0a, Your input is Needed, please be sure to visit us on www.wowinterface.com . all input is welcomed, next stage is Action Bars. Have fun and !!!Good Luck!!!")
end)

local resolHeight = GetScreenHeight()
local resolWidth = GetScreenWidth()
local aspectRatio = (resolWidth/resolHeight)
print(format("If this function works, your aspect ratio is %.2f.", aspectRatio))

--This is the Backdrop Variable--
local backdrop = {
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
tileSize = 32,
edgeSize = 20,
insets = {
left = 4,
right = 4,
top = 4,
bottom = 4,
}
}

local backdropClear = {
--bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
tileSize = 32,
edgeSize = 20,
insets = {
left = 4,
right = 4,
top = 4,
bottom = 4,
}
}
-- This is Left Main Frame Chunk
local frame = CreateFrame("frame", "LeftChatBaseFrame", UIParent)
LeftChatBaseFrame:SetWidth(resolWidth*.34)
LeftChatBaseFrame:SetHeight(resolHeight*.33)
LeftChatBaseFrame:SetPoint("BOTTOMLEFT", UIParent,"BOTTOMLEFT", -6, -6)
LeftChatBaseFrame:SetFrameStrata("BACKGROUND")
LeftChatBaseFrame:SetFrameLevel(1)
LeftChatBaseFrame:SetAlpha(1)
LeftChatBaseFrame:SetBackdrop(backdrop)
-- This is Right Main Frame Chunk
local frame = CreateFrame("frame", "RightChatBaseFrame", UIParent)
RightChatBaseFrame:SetWidth(resolWidth*.34)
RightChatBaseFrame:SetHeight(resolHeight*.33)
RightChatBaseFrame:SetPoint("BOTTOMRIGHT", UIParent,"BOTTOMRIGHT", 6, -6)
RightChatBaseFrame:SetFrameStrata("BACKGROUND")
RightChatBaseFrame:SetFrameLevel(1)
RightChatBaseFrame:SetAlpha(1)
RightChatBaseFrame:SetBackdrop(backdrop)

--set chat frame to proper position
local DummyFrame = CreateFrame("Frame")
DummyFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
DummyFrame:SetScript("OnEvent", function(self, event, ...)
   if (event == "PLAYER_ENTERING_WORLD") then
           ChatFrame1:ClearAllPoints() 
           ChatFrame2:ClearAllPoints()
      ChatFrame1:SetPoint("BOTTOMLEFT", LeftChatBaseFrame, "BOTTOMLEFT", 0, 0)
      ChatFrame1:SetPoint("TOPRIGHT", LeftChatBaseFrame, "BOTTOMLEFT", 451, 241)
      ChatFrame2:SetPoint("BOTTOMLEFT", RightChatBaseFrame, "BOTTOMLEFT", 8, 0)
      ChatFrame2:SetPoint("TOPRIGHT", RightChatBaseFrame, "BOTTOMLEFT", 455, 194)
   end
end)


took the advice on the CAP function, also added in a Register event so it could see it happening

  Reply With Quote
05-25-14, 10:53 AM   #5
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
and the final product, which makes it scale-able to any resolution that the user chooses, on enter world or reload it will auto configure to the resolution they have chosen,
Code:
local DummyFrame = CreateFrame("Frame")
DummyFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
DummyFrame:SetScript("OnEvent", function(self, event, ...)
   if (event == "PLAYER_ENTERING_WORLD") then
   		ChatFrame1:ClearAllPoints() 
   		ChatFrame2:ClearAllPoints()
      ChatFrame1:SetPoint("BOTTOMLEFT", LeftChatBaseFrame, "BOTTOMLEFT", 8, 0)
      ChatFrame1:SetPoint("TOPRIGHT", LeftChatBaseFrame, "BOTTOMLEFT", (resolWidth*.334), (resolHeight*.310))
      ChatFrame2:SetPoint("BOTTOMLEFT", RightChatBaseFrame, "BOTTOMLEFT", 8, 0)
      ChatFrame2:SetPoint("TOPRIGHT", RightChatBaseFrame, "BOTTOMLEFT", (resolWidth*.334), (resolHeight*.252))
   end
end)

whatcha think?
  Reply With Quote
05-25-14, 12:13 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You don't need to check if your event matches "PLAYER_ENTERING_WORLD" because that is the only event your frame is registered for.

Also, unregister that event at the end of your function. Otherwise your code will run on every load screen and it doesn't need to.
__________________
"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
05-26-14, 12:16 PM   #7
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
so you mean something like this?
Code:
local DummyFrame = CreateFrame("Frame")
DummyFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
DummyFrame:SetScript("OnEvent", function(self, event, ...)
   if (event == "PLAYER_ENTERING_WORLD") then
           ChatFrame1:ClearAllPoints() 
           ChatFrame2:ClearAllPoints()
      ChatFrame1:SetPoint("BOTTOMLEFT", LeftChatBaseFrame, "BOTTOMLEFT", 8, 0)
      ChatFrame1:SetPoint("TOPRIGHT", LeftChatBaseFrame, "BOTTOMLEFT", (resolWidth*.334), (resolHeight*.310))
      ChatFrame2:SetPoint("BOTTOMLEFT", RightChatBaseFrame, "BOTTOMLEFT", 8, 0)
      ChatFrame2:SetPoint("TOPRIGHT", RightChatBaseFrame, "BOTTOMLEFT", (resolWidth*.334), (resolHeight*.252))
   end
DummyFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
end)
  Reply With Quote
05-26-14, 12:46 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Yes, but you still don't need to check if the event that fired was "PLAYER_ENTERING_WORLD", unless you're registering more than just that event to your frame.
__________________
"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
05-26-14, 01:31 PM   #9
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
What Seerah is saying is that if you only plan on using this code for PLAYER_ENTERING_WORLD you can bypass the If then statement like so:

Code:
local DummyFrame = CreateFrame("Frame")
DummyFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
DummyFrame:SetScript("OnEvent", function(self, event, ...)
   ChatFrame1:ClearAllPoints() 
   ChatFrame2:ClearAllPoints()
   ChatFrame1:SetPoint("BOTTOMLEFT", LeftChatBaseFrame, "BOTTOMLEFT", 8, 0)
   ChatFrame1:SetPoint("TOPRIGHT", LeftChatBaseFrame, "BOTTOMLEFT", (resolWidth*.334), (resolHeight*.310))
   ChatFrame2:SetPoint("BOTTOMLEFT", RightChatBaseFrame, "BOTTOMLEFT", 8, 0)
   ChatFrame2:SetPoint("TOPRIGHT", RightChatBaseFrame, "BOTTOMLEFT", (resolWidth*.334), (resolHeight*.252))
   DummyFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
end)
__________________
AddOns: Tim @ WoWInterface
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote
05-28-14, 07:58 PM   #10
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by Tim View Post
What Seerah is saying is that if you only plan on using this code for PLAYER_ENTERING_WORLD you can bypass the If then statement like so:

Code:
local DummyFrame = CreateFrame("Frame")
DummyFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
DummyFrame:SetScript("OnEvent", function(self, event, ...)
   ChatFrame1:ClearAllPoints() 
   ChatFrame2:ClearAllPoints()
   ChatFrame1:SetPoint("BOTTOMLEFT", LeftChatBaseFrame, "BOTTOMLEFT", 8, 0)
   ChatFrame1:SetPoint("TOPRIGHT", LeftChatBaseFrame, "BOTTOMLEFT", (resolWidth*.334), (resolHeight*.310))
   ChatFrame2:SetPoint("BOTTOMLEFT", RightChatBaseFrame, "BOTTOMLEFT", 8, 0)
   ChatFrame2:SetPoint("TOPRIGHT", RightChatBaseFrame, "BOTTOMLEFT", (resolWidth*.334), (resolHeight*.252))
   DummyFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
end)
tim thank you much for clerifying thatif you all dont know, the smaller i can make this code and the cleaner it is the better, since i am the only maintainer, its goina be a handful on changes to the API,


makes sens to only check if its only on player enters world instead of every reload
... question, why does everyone code seem so pretty compare to mine hahaha
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Set Script function


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