-
Posted by caelic on Mon, 26 Sep 2011 21:49:41
Hey guys.. I have a question about my addon.. I'm trying to send a random string out of a selection of strings, and its not working.. I had it working a year or so ago, and am trying to get my addon working again.. And for some reason, the randomized settings aren't working..
This is the function..
function NDG_Report() local goldowed = high - low if (goldowed ~= 0) then lowname = lowname:gsub("^%l", string.upper) highname = highname:gsub("^%l", string.upper) local string3 = strjoin(" ", "[ndg]", lowname, "owes", highname, goldowed,"gold.") NDG["stats"][highname] = (NDG["stats"][highname] or 0) + goldowed; NDG["stats"][lowname] = (NDG["stats"][lowname] or 0) - goldowed; SendChatMessage(string3,chatmethod,GetDefaultLanguage("player"));`
What I want it to do is:
` local string1 = strjoin(" ", "[ndg]", lowname, "1", highname, goldowed,"gold.") local string2 = strjoin(" ", "[ndg]", lowname, "2", highname, goldowed,"gold.") local string3 = strjoin(" ", "[ndg]", lowname, "3", highname, goldowed,"gold.") local string4 = strjoin(" ", "[ndg]", lowname, "4", highname, goldowed,"gold.") local string5 = strjoin(" ", "[ndg]", lowname, "5", highname, goldowed,"gold.")
I want it to send one of those local strings.. but.. when I do
SendChatMessage(string[random(1,5)],chatmethod,GetDefaultLanguage("player"));
It doesn't work.. But I'm pretty sure thats what I had before.. I lost my old addons.. and can't find what I had it setup as before.
Any help?
-
Posted by jnwhiteh on Tue, 27 Sep 2011 08:56:05
Well, you can't do this with variables like string1, string2, string3, it's just not the right way to do it. What you want to do instead is:
local strings = {} strings[1] = "First string" strings[2] = "Second string" strings[3] = "Third string" strings[4] = "Fourth string" strings[5] = "Fifth string"
Then you can do:
SendChatMessage(strings[random(1,5)], chatmethod, GetDefaultLanguage("player"));
Or more robustly:
SendChatMessage(strings[random(1,#strings)], chatmethod, GetDefaultLanguage("player"));
So you don't have to edit the SendChatMessage call every time you add a string to the table.
-
Posted by caelic on Tue, 27 Sep 2011 17:00:49
Hey, thank you. Its working great. Appreciate it.
-
Posted by deltoide on Mon, 21 Nov 2011 07:25:42
Here functions perfectly well, just one question. How to do it constantly send messages every 30 minutes? Is it possible?
-
Posted by jnwhiteh on Mon, 21 Nov 2011 07:51:08
You can use something like Using an OnUpdate timer to do something periodically.
-
Posted by deltoide on Mon, 21 Nov 2011 11:17:17
Thank you friend is working perfectly, I'm just having trouble to emphasize words, if I put a word it does not appear sharp, and if I put it way down, with the UTF-8 code addon shows an error. help me
strings[2] = "\195\137 proibida a comercializa\195\167\195\163o de objetos de sua profiss\195\163o na guilda."
-
Posted by jnwhiteh on Mon, 21 Nov 2011 11:22:23
I don't understand what you're asking. Without the error, there's not much I can say.
Also, I should say now that there's no point in you going through and removing all of your posts from this website, I will revert any such edits, so there's no sense in wasting any of our time.
-
Posted by deltoide on Mon, 21 Nov 2011 11:48:29
I believe I have found the failure at any given time, put the character " for this reason was giving conflict.
What about post's that you recovered, I do not know what it is, but anyway, I apologize for my mistake possible.
And thanks again for your help, is working perfectly.
-
Posted by deltoide on Mon, 21 Nov 2011 18:13:51
Why don't work?
SendChatMessage("I am Rogue Sub, the DPS", "CHANNEL", GetDefaultLanguage("player"), GetChannelName("General"));
I try
SendChatMessage("I am Rogue Sub, the DPS", "CHANNEL", GetDefaultLanguage("player"), "1");
And work
-
Posted by jnwhiteh on Tue, 22 Nov 2011 09:07:14
I don't know, does GetChannelName("General") return anything in the case you're testing it? The documentation pretty clearly indicates that it takes the channel number as an argument, so you'd need to ensure you have that, which is why the second example works.