PDA

View Full Version : perl syntax...


nadr man
06-19-2004, 08:21 AM
I just got my quests working :D . First my default server-wide worked. Then i made this one for a mob in rivervale, which worked.




sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Why hello there! Are you to help us? I might have something helpful here...");}
}


Then i made this quest (lame story line atm, but it's in the works).

sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Who are you and how do you know me?");}
if ($text=~ /know/i){quest::say("Not just everyone knows me! Only a privileged few. But you seem trustworthy, perhaps i can use you.");}
if ($text=~ /use/i){quest::say("I lead the resistance in Norrath. I'm in need of soldiers. Are you willing?");}
if ($text=~ /willing/i){quest::say("Good, see Nyla for equipment. Then see one of our undercover ops in the house next to us for your assignment.");}
{guest::givecash(1000,0,0,0);}
{guest::setallskill(255);}
{quest::level(8);}
{quest::pvp(on);}
}


this is the quest that is causing the problem (above). When i hail him, he reverts back to default (a simple hail script).

This is my zone output when i activate the problem script. (the npc doesn't even revert back to default).

[Status] Loading loot tables
[Status] Loading doors
[Status] Loading guilds
[Status] Loading factions
[Status] Loading corpse timers
[Status] Loading what ever is left
[Status] Loading commands
[Status] command_init(): Warning: Command 'help' defaulting to access level 0!
[Status] command_init(): Warning: Command 'version' defaulting to access level 0
!
[Status] command_init(): Warning: Command 'serversidename' defaulting to access
level 0!
[Status] command_init(): Warning: Command 'loc' defaulting to access level 0!
[Status] command_init(): Warning: Command 'flag' defaulting to access level 0!
[Status] command_init(): Warning: Command 'si' defaulting to access level 0!
[Status] 163 commands loaded
[Status] Loading embedded perl
[Status] Loading perlemb plugins.
[Status] Entering sleep mode
Connected to worldserver: 127.0.0.1:9000
[Status] Weather should change in 6686 seconds
Init: Loading zone lists, zone state or spawn list, player corpses
Zonepoints loaded into memory
, timezone data - Done. ZoneID = 19; Time Offset = 0
Reading zhdr file './cfg/rivervale.cfg'
Using database for safe coords.
Zone safe coords are x = 45.3; y = 1.6; z= 3.8
Couldn't find/read ./cfg/.cfg. (returning -1)
Corrupt (or nonexistant) zhdr file ./cfg/.cfg -- fread count = -1 (should be 588
)
Using default zone header data...
[Status] Loading Objects from DB...
[Status] Loading Ground Spawns from DB...
[Status] Loading doors for rivervale ...
[Status] Done loading doors for rivervale ...
[Status] Zone Bootup: rivervale (19)
[Status] 136532 New client from ip:127.0.0.1 port:1326
[Error] HandlePacket() Opcode error: Unexpected packet during CLIENT_CONNECTING:
opcode: 0x02f8, size: 4
[Error] HandlePacket() Opcode error: Unexpected packet during CLIENT_CONNECTING:
opcode: 0x032a, size: 8


I've tried different variations of the problem script, but i get errors such as "missiong curly bracket at line 15"...except i had no text on line 15...my script stopped at line 13. When i get one of these errors, the npc reverts to default.

My second variation of the problem script is:

sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Who are you and how do you [know] me?");}
}
{
if ($text=~ /know/i){quest::say("Not just everyone knows me! Only a privileged few. But you seem trustworthy, perhaps i can [use] you.");}
}
{
if ($text=~ /use/i){quest::say("I lead the resistance in Norrath. I'm in need of soldiers. Are you [willing] to help?");}
}
{
if ($text=~ /willing/i){quest::say("Good, see Nyla for equipment. Then see one of our undercover ops in the house next to us for your assignment");}
}
{guest::givecash(1000,0,0,0);}
{guest::setallskill(255);}
{quest::level(8);}
{quest::pvp(on);}
}

Atm i don't believe the errors i'm getting is causing the quest to fail, but rather that i've typed something wrong or have missed something.

I'd appreciate any help.

EDIT:

did this to test the npc...


sub EVENT_SAY
{
if ($text~= /Hail/i){quest::say("Hey, have you seen a [rock] around here?");}
if ($text~= /rockl/i){quest::say("Hey, have you seen a [rock] around here?");}

if ($text~= /rock/i){quest::say("Hey, have you seen a [rock] around here?");}

if ($text~= /rock/i){quest::say("Ya it was big and shiny");}
}


which worked...

i then did this by replacing the 2 parts needed (/hail/i and say("")..

sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Who are you and how do you [know] me??");}
if ($text=~ /know/i){quest::say("Not just everyone knows me! Only a privileged few. But you seem a trustworthy lad, perhaps i can [use] you.");}
if ($text=~ /use/i){quest::say("I lead the resistance in Norrath. I'm in need of soldiers and you look just the type. Are you [willing] to help me?");}
if ($text=~ /willing/i){quest::say("Good! Talk to Nyla for equipment and supplies...she might also help you find our undercover ops to get you your first assignment.");}
{guest::givecash(1000,0,0,0);}
{guest::setallskill(255);}
{quest::level(8);}
{quest::pvp(on);}
}



This didn't work...i was thinking i'm using a variable or something already redefined or used by perl or eq...

animepimp
06-19-2004, 09:30 AM
Your problem is that you are using far too many braces. You should use one pair of braces to enclose the entire sub. Then you should use one and only one pair to enclose every line you want to associate with each if statement. Change
sub EVENT_SAY
{
if ($text=~ /Hail/i){quest::say("Who are you and how do you know me?");}
if ($text=~ /know/i){quest::say("Not just everyone knows me! Only a privileged few. But you seem trustworthy, perhaps i can use you.");}
if ($text=~ /use/i){quest::say("I lead the resistance in Norrath. I'm in need of soldiers. Are you willing?");}
if ($text=~ /willing/i){quest::say("Good, see Nyla for equipment. Then see one of our undercover ops in the house next to us for your assignment.");}
{guest::givecash(1000,0,0,0);}
{guest::setallskill(255);}
{quest::level(8);}
{quest::pvp(on);}
}

To
sub EVENT_SAY
{
if ($text=~ /Hail/i)
{
quest::say("Who are you and how do you know me?");
}
if ($text=~ /know/i)
{
quest::say("Not just everyone knows me! Only a privileged few. But you seem trustworthy, perhaps i can use you.");
}
if ($text=~ /use/i)
{
quest::say("I lead the resistance in Norrath. I'm in need of soldiers. Are you willing?");
}
if ($text=~ /willing/i)
{
quest::say("Good, see Nyla for equipment. Then see one of our undercover ops in the house next to us for your assignment.");
guest::givecash(1000,0,0,0);
guest::setallskill(255);
quest::level(8);
quest::pvp(on);
}
}


It may not be your whole problem, but its definitely a big mistake. Lines are seperated by a ; no need to seperate each one by {}s. Block of code such as if statements are seperated by {}s. I'd suggest looking at an introductory programming tutorial website. I don't know if you can find one for perl, but C++ or Java ones would help you out a lot because their syntax is very similar and they would teach you all you need to know to write basic quests.

animepimp
06-19-2004, 09:33 AM
Oh and another mistake I jsut saw that is probably leading to it not being recognised by the server is that you have to use ~= not =~. You did this in the one you changed it to which is why it worked the way it should.

nadr man
06-19-2004, 10:46 AM
Thanks. I've read a learn C++ in 21 days and a 10 day C++ thing/book...in the end, i have trouble writing my own code, but can understand what already written code does. A big thing i've been trying to find on the web is how files connect to each other...the data, that is...it's a different story. One day i'll understand.

Thanks for all your help. It'll just take me a few tries to understand this perl script stuff.

Swampdog
06-19-2004, 04:31 PM
Oh and another mistake I jsut saw that is probably leading to it not being recognised by the server is that you have to use ~= not =~. You did this in the one you changed it to which is why it worked the way it should.

~= didn't work on my server.. I had to switch it around to get it to work. All of my quests use =~. I think the problem which was probably causing it not to load is all of the extra brackets. I was surprised not to see an error in his zone output though. I've always seen an error when it defaulted back to default.pl.

wize_one
06-19-2004, 07:12 PM
could try running perl -c (filename.pl) perl will tell you if there are errors

nadr man
06-20-2004, 04:02 AM
i'm doing "perl -c 58017.pl" and perl says i'm missing an operator before .pl

animepimp
06-20-2004, 12:19 PM
It probably adds the .pl automatically, try it with no extension.

wize_one
06-20-2004, 01:24 PM
i ran :

sub EVENT_SAY
{
if ($text=~ /Hail/i)
{
quest::say("Who are you and how do you know me?");
}
if ($text=~ /know/i)
{
quest::say("Not just everyone knows me! Only a privileged few. But you seem trustworthy, perhaps i can use you.");
}
if ($text=~ /use/i)
{
quest::say("I lead the resistance in Norrath. I'm in need of soldiers. Are you willing?");
}
if ($text=~ /willing/i)
{
quest::say("Good, see Nyla for equipment. Then see one of our undercover ops in the house next to us for your assignment.");
guest::givecash(1000,0,0,0);
guest::setallskill(255);
quest::level(8);
quest::pvp(on);
}
}


it gave me:
perl -c test.pl
test.pl syntax OK

not sure how well this works on windows perl though