View Single Post
  #12  
Old 07-13-2009, 04:29 PM
pfyon's Avatar
pfyon
Discordant
 
Join Date: Mar 2009
Location: Ottawa
Posts: 495
Default

Quote:
Originally Posted by Dibalamin View Post
How can you make it store a text string? Been thinking about a bot to do guilds.
Under EVENT_SAY you should be able to just do
Code:
$myString = $text;
That'll just store the current text since it would be overwritten whenever someone said something to the npc with the current text. A better approach would be to put it in an if block with a regex to check for a string like "Guildname: xxxxxx" then store the xxxxxx part with another regex.
Code:
if($text =~/<some regex to check guildname>/i)
{
$text =~/<regex to pull out the guildname>/;
$guildname = $text;
}
Again, no real experience using perl or regular expressions, so I'm not sure exactly how you'd do that. One way would be to store the initial say text in a temporary variable since performing the regex puts the output in the variable that you perform it on (I think, so $text =~ something modifies $text to be the output of the expression).

Kinda getting over my head with regular expressions and perl in this thread, I'm just waiting for someone who actually uses it regularly to come in and say "no, that's all wrong". :p

Also, not sure if it's good programming practice with perl, but you could declare the variable as a global variable (outside EVENT_SAY, like at the top of the script) so it can be accessed from other events.
Reply With Quote