I am confused with three global variables, $monstersList, @monstersID and %monsters.
What differences in these three global variables, $monstersList, @monstersID and %monsters ?
For example:
my $monster1 = $monstersList->getByID($mID);
my $monster2 = $monsters{$mID};
Is $monster1 the same with $monster2 ?
Then, how about the @monstersID ?
When do "$monstersList->clear();" in function.pl, does nead to clear the %monsters and @monstersID ?
Confused with $monstersList, @monstersID, %monsters
Moderator: Moderators
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
-
- Developers
- Posts: 1798
- Joined: 05 Dec 2008, 05:42
- Noob?: Yes
Re: Confused with $monstersList, @monstersID, %monsters
$monstersList is an ActorList, indexed by server ID ($actor->{ID}).
Usually you need to use this list, with ->getItems or ->getByID.
@monstersID is an array of the same Actor objects, but indexed by openkore's UI ID (usually something like 0, 1, 2...; $actor->{binID}).
This list is useful when you need to find monster by that user interface ID, like when handling a console command.
%monsters is a hash indexed by server ID. It doesn't do anything new (you should use $monstersList) and it's deprecated, see the related commit: http://openkore.svn.sourceforge.net/vie ... ision=4305
The same is for other similar lists (items, players etc).
Usually you need to use this list, with ->getItems or ->getByID.
@monstersID is an array of the same Actor objects, but indexed by openkore's UI ID (usually something like 0, 1, 2...; $actor->{binID}).
This list is useful when you need to find monster by that user interface ID, like when handling a console command.
%monsters is a hash indexed by server ID. It doesn't do anything new (you should use $monstersList) and it's deprecated, see the related commit: http://openkore.svn.sourceforge.net/vie ... ision=4305
The same is for other similar lists (items, players etc).
You should not change @monstersID or %monsters anywhere since they're being maintained automatically with this:sofax222 wrote:When do "$monstersList->clear();" in function.pl, does nead to clear the %monsters and @monstersID ?
Code: Select all
foreach my $list ($itemsList, $monstersList, $playersList, $petsList, $npcsList, $portalsList, $slavesList) {
$list->onAdd()->add(undef, \&actorAdded);
$list->onRemove()->add(undef, \&actorRemoved);
$list->onClearBegin()->add(undef, \&actorListClearing);
}
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
Re: Confused with $monstersList, @monstersID, %monsters
I got it !!
Thanks a lot !
Thanks a lot !