PDA

View Full Version : Dynamic PC Input Menu System


Deimos
08-17-2008, 04:28 AM
And well.. the if statement always rings true no matter what... the loops are fine.. everything is fine.. it's just when I change it to any sort of array... it auto checks true..

><
><

http://rafb.net/p/APmJKe82.html

><
><

Any thoughts? I'm thinking of maybe using something like push to convert it to a table.. but ><.... I'd rather not... : o

Deimos
08-17-2008, 07:19 PM
Updated Link:
http://rafb.net/p/DK2g2S93.html

trevius
08-18-2008, 04:50 PM
Posting the code here since it makes it more likely for people to check it. It should help increase your chance of someone helping.

my $greencolor = 2;
my $bluecolor = 4;
my $greycolor = 1;
my $pinkcolor = 5;
my $whitecolor = 7;
my @menu =
(
["Main Menu",3,"[Task Menu]","[Server Information Menu]","[Logout]"],
["Task Menu",1,"[Main Menu]"]
);
sub accessmenu($)
{
my $tableindex = 0;
my $start = 0;
my $end = 0;
while($end == 0)
{
$client->Message($greencolor,"Table Index: $tableindex -- End: $end -- Input: $_[0] -- Menu: $menu[$tableindex][0]");
if($menu[$tableindex][0] == $_[0])
{
$end = 1;
}
elsif($menu[$tableindex][1] == 0)
{
$client->Message($greycolor,"$_[0] not found.");
$end = 2;
}
$client->Message($greencolor,"Table Index: $tableindex -- End: $end -- Input: $_[0] -- Menu: $menu[$tableindex][0]");
} continue {$tableindex++;}
if($end == 1)
{
while($start <= $menu[$tableindex][1])
{
$client->Message($bluecolor,$menu[$tableindex-1][$start + 2]);

} continue {$start++;}
}
}
sub EVENT_SAY
{
if($text=~/wu40fjoisdjfiosjiofjsd/i)
{
}
else
{
accessmenu($text);
}
}

Deimos
08-18-2008, 07:59 PM
Oh I fixed it, I forgot to post : O

it was =~ quest text, dumb on my part ; o

But I got cool news, this has evolved into quite a project ^_^.

I'm making a persistent in-game PERL DB off of this, lolz... it'll be better than global variables in a way that you can create data structures and so on : D.

I tested it : P. I created a table, stored it, and had another NPC retrieve it. Worked like a charm : D.

Oh well, I'll submit this when it's done kk, so you can all have fun ^_^. You can also use it for localized instances and local tables within NPCs ^)^. It also takes away the need for the thousands of if statements ><
if($text=~/hail/i) or w/e. You can just have a sub EVENT_SAY and add these statements to the table. You'll also be able to manipulate it more by adding in custom properties, taking properties from other areas, and so on, for example, internal status requirements, how much the NPC likes you, the NPCs mood, the status of the player, and w/e you want, and instead of having these each as an if statement, when you put them in the table it'll autocheck to make sure all of these things are true or false or whatever you want it to be ^_^.

Oh well, back to my little project *is excited*