User Control Panel
Advertisements

HELP US, HELP YOU!

independent variables

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
josoers
Newbie
Newbie


Joined: 15 Jul 2005
Posts: 2

Reputation: 9.9Reputation: 9.9Reputation: 9.9Reputation: 9.9Reputation: 9.9Reputation: 9.9Reputation: 9.9Reputation: 9.9Reputation: 9.9

PostPosted: Fri Jul 15, 2005 8:45 am    Post subject: independent variables Reply with quote

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
Sentinel


Joined: 19 Jul 2004
Posts: 556
Location: Los Angeles, CA
Reputation: 50.7
votes: 1

PostPosted: Fri Jul 15, 2005 4:10 pm    Post subject: Reply with quote

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
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Mon Jul 18, 2005 3:38 pm    Post subject: Reply with quote

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
Sentinel


Joined: 19 Jul 2004
Posts: 556
Location: Los Angeles, CA
Reputation: 50.7
votes: 1

PostPosted: Mon Jul 18, 2005 5:44 pm    Post subject: Reply with quote

you can also declear it as global with

my $userdata = {};

if you do it outside any subs
Back to top
m6246
Newbie
Newbie


Joined: 08 Jul 2005
Posts: 15

Reputation: 10.4

PostPosted: Mon Jul 18, 2005 10:57 pm    Post subject: Reply with quote

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
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Mon Jul 18, 2005 11:45 pm    Post subject: Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group