|
| Author |
Message |
josoers Newbie

Joined: 15 Jul 2005 Posts: 2
         
|
Posted: Fri Jul 15, 2005 8:45 am Post subject: independent variables |
|
|
Ok so i made a game for MSN, but things are going weird!
im sure this is because of variables being shared by all open conversations.
-----------------------
my $var = 'A';
....
sub Message {
....
if ($message =~ /^set_to_A$/i ){
$var = 'A';
}
if ($message =~ /^set_to_B$/i ){
$var = 'B';
}
}
------------------
Now when i run the bot and someone opens a conversation and sets the var to A, the var will be A to all conversations.
I want the var to be independent and unique to all conversations, how do i do this?? |
|
| Back to top |
|
 |
mattaustin Sentinel

Joined: 19 Jul 2004 Posts: 556 Location: Los Angeles, CA
  votes: 1
|
Posted: Fri Jul 15, 2005 4:10 pm Post subject: |
|
|
you could add it to the $self hash...
$self->{var} = "A";
that would make it only the current convo.. |
|
| Back to top |
|
 |
Cer Upgraded Agent

Joined: 03 Feb 2004 Posts: 3776 Location: Michigan
  votes: 4
|
Posted: Mon Jul 18, 2005 3:38 pm Post subject: |
|
|
Sometimes (with the newer MSN's especially) sockets are closed after only so many seconds of not chatting.
You can make a global user variables hash, declared like this:
| Code: | | our $userdata = {}; |
(in your main bot's code, probably)
And you could store data per user. In the MSN Message handlers you get the user's e-mail (usually $user or $client or something)... to store info under that user:
| Code: | | $userdata->{$user}->{var} = 'value'; |
Where "var" is whatever your variable name would've been (without the $) and "value" is the variable's value, of course. _________________ Current Site (2008) http://www.cuvou.com/ |
|
| Back to top |
|
 |
mattaustin Sentinel

Joined: 19 Jul 2004 Posts: 556 Location: Los Angeles, CA
  votes: 1
|
Posted: Mon Jul 18, 2005 5:44 pm Post subject: |
|
|
you can also declear it as global with
my $userdata = {};
if you do it outside any subs |
|
| Back to top |
|
 |
m6246 Newbie

Joined: 08 Jul 2005 Posts: 15
 
|
Posted: Mon Jul 18, 2005 10:57 pm Post subject: |
|
|
when i use $self->{var} = 'a';
are these vars hashes deleted when i close the convo or do i need to delete them myself? (to save memory) |
|
| Back to top |
|
 |
eric256 The Keymaker

Joined: 03 May 2006 Posts: 2292 Location: Colorado
     
|
Posted: Mon Jul 18, 2005 11:45 pm Post subject: |
|
|
If you use $self then it will be deleted when the conversation is over. If you use a seperate hash you will have to delete it on your own. _________________ Eric256
Proud previous owner and current admin of Bot-depot.com |
|
| Back to top |
|
 |
|