[Crossfire-wiki] [Crossfire DokuWiki] page added: user:mhoram:scripts:subs.pl
no-reply_wiki at metalforge.org
no-reply_wiki at metalforge.org
Mon Feb 19 15:17:06 CST 2007
A page in your DokuWiki was added or changed. Here are the details:
Date : 2007/02/19 15:17
User : mhoram
Edit Summary: created
====== subs.pl ======
This is a small assortment of subroutines that I call often in client-side scripts, so I put them together here in one place. To use this file, put it in the same directory as your scripts, and include it like this: <code perl>require "./subs.pl";</code>
====== Code ======
<code perl>
# Subroutines for use in client-side crossfire scripts
sub wait_for_server {
print "watch comc\n";
my $res = <STDIN>;
print "unwatch comc\n";
}
# request_line()
# Request one line of information from the client
#
# @param $request
# Information to request
#
# Returns the reply as a scalar
#
sub request_line1 {
my $request = "@_"; # Join any arguments with spaces
my @lines;
print "request $request\n";
while(<STDIN>){
if( /^request $request (.+)$/ ){
return $1;
}
}
return undef;
}
sub request_line {
my $request = shift;
print "request $request\n";
my $reply;
while( $reply = <STDIN> ){
# LOG($reply);
chomp $reply;
last if( $reply =~ s/^request $request // );
}
return split ' ', $reply;
}
sub draw {
my $color = shift;
my $line = shift;
print "draw $color $line\n";
}
sub issue {
for (@_) {
print "issue 1 1 $_\n";
wait_for_server();
}
}
sub LOG {
print STDERR @_, "\n";
}
1;
</code>
IP-Address : 206.71.197.56
Old Revision: none
New Revision: http://wiki.metalforge.net/doku.php/user:mhoram:scripts:subs.pl
--
This mail was generated by DokuWiki at
http://wiki.metalforge.net/
More information about the crossfire-wiki
mailing list