Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
rythin
Beginner


Joined: 12 Jul 2011
Posts: 13

PostPosted: Sun Oct 30, 2011 5:48 pm   

Database of enemies - problem with deleting a position from a list.
 
Hi!

I have a list of enemies that the script dynamically creates triggers from. It goes like that:

Code:
ALIAS "DB":

#if %1="add" {
temp=%numitems(@ListDescs)+1
ListDescs.@temp=%2 %3 %4
ListNames.@temp=%5
ListGuilds.@temp=%6
}
#if %1="delete" {
#delnitem ListDescs %ismember(%2,@ListNames)
#delnitem ListNames %ismember(%2,@ListNames)
#delnitem ListGuilds %ismember(%2,@ListNames)
}


So if I have following enemies:
- db add big fat dwarf Jimmie Guild1,
- db add small tiny elf Carol Guild1,
- db add old merry dwarf David Guild2,

My vars are like:
ListDescs="big fat dwarf|small tiny elf|old merry dwarf"
ListNames="Jimmie|Carol|David"
ListGuilds="Guild1|Guild1|Guild2"

Then I create all bunch of triggers:
Temp1=@ListDescs.%i
Temp2=@ListNames.%i
#EXEC %concat("#trigger {",@ListDescs.%i,"} {#sub {",@Temp1," %ansi(white,red)~(",@ListGuilds.%i," - ",@Temp2"~)}}")}


And now two questions:
1. Is there a better, faster, more efficient way to do that?
2. All works fine and dandy, but whenever I delete someone from the list "db del Carol", it deletes entries from ListNames, ListDescs, but ListGuilds for some reason remains untouched and screws up quickly. I believe it may be so because multiple entries within ListGuilds may be the same. How should I handle deleting items from those lists?

Thanks in advance,
R.
Reply with quote
ins0mnia
Novice


Joined: 23 Jan 2011
Posts: 42
Location: United States

PostPosted: Sun Oct 30, 2011 6:16 pm   
 
I would either
a) use a single list with a delimiter of your own to tell where to color on the trigger
ListEnemies={big fat dwarf,Jimmie,Guild1|small tiny elf,Carol,Guild1|old merry dwarf,David,Guild2}

b) use a single database variable, if the descs never change
ListEnemies={big fat dwarf Jimmie=Guild1|small tiny elf Carol=Guild1|old merry dwarf David=Guild2}

c) switch to a sql database

Also, you can have one trigger that just matches an item from @ListDescs then grab the other values with the same technique you used in your alias %ismember(%2,@ListNames)
You don't need a trigger for each item
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sun Oct 30, 2011 6:20 pm   
 
You may want to look into the #additem command for adding. As for the delete problem, it happens because you're deleting from ListNames before ListGuilds. Your %ismember on the ListGuilds line is failing because you've already removed that entry in ListNames in the previous line of code. Just change the order and it should be fine.
Reply with quote
rythin
Beginner


Joined: 12 Jul 2011
Posts: 13

PostPosted: Sun Oct 30, 2011 6:26 pm   
 
ins0mnia,
Thanks a dozen. That was really informative! I think I'll go with option A :)

Daern,
Wow, of course! Haha, didn't catch that one. Thanks.
Reply with quote
ins0mnia
Novice


Joined: 23 Jan 2011
Posts: 42
Location: United States

PostPosted: Sun Oct 30, 2011 7:06 pm   
 
Yeah good catch. I saw the lack of #additem, other than saving a line of code, it's just a different syntax I believe. #additem would make for cleaner syntax though.

I would switch to a sql database if you can grok it, it allows you to extend without making more and more lists. You could start tracking kill counts for example. It's really up to you and how much you intend to add.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net