This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Live
PTR
10.2.7
PTR
10.2.6
Beta
How to ping the minimap?
Return to board index
Post by
RedwoodElf
I've looked through the API, and I don't see what function does this, but how would you make an addon "ping" the minimap (I.E. Make a blip on the minimap screen as if you had clicked on it) The minimap isn't part of the game world, but part of the UI, so there should be a way to do it, but I don't see any "PingMiniMap(x,y)" function.
Post by
73066
This post was from a user who has deleted their account.
Post by
RedwoodElf
Ah, OK...missed it the first time I looked...now all I have to do is figure out if the X,Y change, depending on the minimap rotation settings (Screen coordinates, or world coordinates)
Post by
RedwoodElf
Tried making this little mini addon just to test it out...but it's not even registering the /ping slash command in WOW, even though I defined it TWICE as far as I can tell...I'm a Java/C++ programmer, and Lua's syntax is way too "loose" for my taste...it's like trying to read BASIC written by a dyslexic with a love of spaghetti code....
-- Map Ping --
SLASH_PING1 = "/ping"
SlashCmdList = function(x,y)
ChatFrame1:AddMessage(x)
ChatFrame1:AddMessage(y)
Minimap:PingLocation(x,y)
end
Fiddled with this dang thing for 4 hours straight, and can't figure out what I'm doing wrong, unless my Lua manual is just wrong on how this works or isn't explaining how slash commands are implemented correctly. You'd think with a 4 year computer science degree and a manual, it would be really EASY to get a simple "Get two variables from a command line and send them to a function" to work.
It's not even recognising /ping as a slash command, let alone actually doing anything with it...
Post by
RedwoodElf
Ok...Pretty much found out what was wrong...there was a typo in the TOC file...instead of trying to load "ping.lua" it was trying to load "ping.luo"
I KNEW it had to be something incredibly simple...now it responds to the command, but locks up the chat window (the "/ping #,#" slash command stays on the typing line) with the following code:
-- Map Ping --
SLASH_PING1 = "/ping"
SlashCmdList = function(arg)
local str = arg
ChatFrame1:AddMessage(arg)
local x,y = str.match("(%d),(%d)")
ChatFrame1:AddMessage(x)
ChatFrame1:AddMessage(y)
Minimap:PingLocation(x,y)
end
However, I can't get the darn thing to load the X,Y values correctly. If I type:
/ping 5,5
it prints out just
5,5
and doesn't ping the map, and (as I said) the chat window will still have "/ping #,#" in it. I put the chat message commands in there to try to figure out where it was locking up, as I SHOULD have gotten:
5,5
5
5
So I can see that it's locking up on the assignment:
local x,y = str.match("(%d),(%d)")
If I read my Lua manual correctly, this should search the string named 'str' for two numbers, separated by a comma, and assign them to X and Y respectively.
Anyone here a proficient Lua programmer who can tell me exactly what's going wrong here? This is just about the simplest function I can imagine to test pinging the minimap, and it's just not cooperating.
Post by
4466
This post was from a user who has deleted their account.
Post by
RedwoodElf
You're unnecessarily assigned the argument to the slash command to a variable. Also, if you want to use a method on a string object like you are with str.match, I believe it needs to be of the form str:match. Try this...
-- Map Ping --
SLASH_PING1 = "/ping"
SlashCmdList = function(loc)
ChatFrame1:AddMessage(loc)
local x,y = string.match(loc,"(%d),(%d)")
ChatFrame1:AddMessage(x)
ChatFrame1:AddMessage(y)
Minimap:PingLocation(x,y)
end
Actually, I only did that to see if, for some reason, Lua didn't let you use the arguments directly. Since Lua syntax is so loose and the way it handles variables is so strange (I'm used to "an integer is an integer, the program won't even try to put a string in there" and "put a semicolon between statements" type languages) Since that did NOT appear to be the problem, it is, indeed, unnecessary to assign it to a variable.
I'll give that a try when I get back home. The way the programming manual demonstrated "str.match" left out the <varname> part of str.match(<varname>,"<Pattern>")
Post by
Wanderingfox
Believe it or not, typed languages are more rare than untyped languages these days :P
Post by
RedwoodElf
What I wanna know is WTF lua doesn't seem to support explicit argument assignments, like this:
-- Map Ping --
SLASH_PING1 = "/ping"
SlashCmdList = function(x,y)
Minimap:PingLocation(x,y)
end
Since Lua treats strings and numbers if possible, logically, this (or something like it) should work. For some reason, the geniuses who designed Lua apparently decided that you have to tokenize your own input.
Post by
Wanderingfox
What I wanna know is WTF lua doesn't seem to support explicit argument assignments, like this:
-- Map Ping --
SLASH_PING1 = "/ping"
SlashCmdList = function(x,y)
Minimap:PingLocation(x,y)
end
Since Lua treats strings and numbers if possible, logically, this (or something like it) should work. For some reason, the geniuses who designed Lua apparently decided that you have to tokenize your own input.
That's not how untyped variables work. The VARIABLE does not have a type, the DATA it stores does.
If you pass "3" and "8" to that function, it will try to call PingLocation("3", "8"). It might seem stupid or uesless to do that at first, but what if I gave your function this input "-2,301" is that the number -2,301 or is it a coordinate pair of -2 and 301 or is it a number at all? Same goes with something like "10101101" is that the number 10,101,101 or is it 173 or is it a bit mask and not even a number?
Even in C, you'd need to EXPLICITLY type cast those variables into INTs before you could call that function.
Post by
4466
This post was from a user who has deleted their account.
Post by
RedwoodElf
well according to the Lua manual I have, the string "8" is automatically converted into a number if you attempt to perform a mathematical calculation on it, and then back to a string if you try to perform a string function on it.
Guess I'm still too C++/Java oriented to really do much lua...thought I'd be able to jump right in, but looks like I'll have to Dig through the manual page by page instead of simply looking things up in the index...drattit.
Post by
Wanderingfox
But you're not doing a mathematical calculation on it, you're passing it as an arguement, and I'd wager that the PingLocation method is checking it's values to ensure it's only getting valid inputs :P
Post by
RedwoodElf
Gah...In Java/C++ whoever wrote PingLocation would have taken into account different arguments with multiple function definitions, like:
Function PingLocation (char[] XY) /* (Definition to handle a string argument and tokenize it) */
Function PingLocation (int X,Y) /* (Definition to handle two integer arguments) */
Function PingLocation (real X,Y) /* (Definition to handle Two real number arguments) */
Guess this probably CAN Be done...but I'll need to study up more on Lua to figure out how multiple function defs are handled...
Post by
Wanderingfox
Also, the Ace or Rock frameworks would probably be something worth looking into. I doubt the addon you're writing at the moment is actually anything more than a test, but if you ever decide to write a fulll addon, a framework can drastically reduce the amount of code you need to write.
For example, the entire thing you wrote for handling that slash command, is done like this using Ace3:
Ping = LibStub("AceAddon-3.0"):NewAddon("Ping", "AceConsole-3.0")
Ping:OnInitialize()
-- Register slash commands
self:RegisterChatCommand("ping", "PingMap")
end
-- Required by the Ace Framework
Ping:OnEnable() end
Ping:OnDisable() end
-- Slash Command Handler
Ping:PingMap(input)
if input or input:trim() ~= "" then
Minimap:PingLocation(input:match("(%d),(%d)"))
self:Print("Pinged the map")
end
end
That's an EXTREMELY simple example, so it's hard to see the actual benifits (since the overhead of registering a new ace addon is larger than the code the addon runs), but when you get to dealing with saved variables and especially stuff like profiles, it greatly simplifies your code.
Post by
Wanderingfox
Gah...In Java/C++ whoever wrote PingLocation would have taken into account different arguments with multiple function definitions, like:
Function PingLocation (char
It's your responsibility as the caller of the function to provide the proper inputs. The only thing the author of PingLocation needs to worry about is if the data you gave is valid or not, he shouldn't need to worry about converting it unless that's part of the intended design of the function (which given that coords are always numbers, I doubt it is).
Post by
RedwoodElf
Well this one does what I originally wanted it to do, so I could test to see if it used world coordinates or screen coordinates (It uses screen coordinates, so it will require some trigonometry to get the ping to come out in world coordinates if the player has the minimap rotation function turned on)
-- Map Ping --
SLASH_PING1 = "/ping"
SlashCmdList = function(xyinput)
local x,y = string.match(xyinput,"(%-?%d*%.?%d*),(%-?%d*%.?%d*)")
Minimap:PingLocation(x,y)
end
Post by
Wanderingfox
Of course, I was just suggesting some further material if you decided to take the next step into full addon authoring :P
Post by
sahaya
try this site it will help you... (##RESPBREAK##)8##DELIM##asakawa##DELIM##You're linking a site that clearly has no relevance to the topic which is enough to make me suspicious, never mind the fact that it's a necro.
New users are not allowed to share links with the forum so I suggest you refrain from doing so and check out the .
Post Reply
This topic is locked. You cannot post a reply.