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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
talonnb
Apprentice


Joined: 30 Oct 2004
Posts: 127

PostPosted: Sat Apr 21, 2007 1:50 pm   

Arrays and Manipulation
 
I currently have a need where I'd like to be able to store certain triggers within a array or stringlist whichever works and want to be able to check if a certain phrase is among them. I made up a test one to see if I could get it to work:

What I see in game:

The following players from the Daru are online:
Master Miran, Seeker of Purity.
Purifying Flame, Grand Master Kylan, fio Naecelm Ciehianari.
Talonnb Silverain, Auresian Avenger.

So, I made a stringlist with those three names in it. And did this.

The following players from the Daru are online:$(*)$(*)$(*)$ - Trigger
#echo %1
#echo %2
#echo %3
#echo %ismember( %1, @guildmembers)
#echo %ismember( %2, @guildmembers)
#echo %ismember( %3, @guildmembers)

What I get as an output:
Master Miran, Seeker of Purity.
Purifying Flame, Grand Master Kylan, fio Naecelm Ciehianari.
Talonnb Silverain, Auresian Avenger.
0
0
0

So I'm just wondering, is this due to the fact they are strings? %ismember only work for single words?
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sat Apr 21, 2007 2:05 pm   
 
Just a thought but maybe for sake of recording more info, you'd be better off using database variables instead?
Use %addkey for adding the stuff you need and %iskey to check if the stuff you're seeing is in db, accordingly.


Prog
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
talonnb
Apprentice


Joined: 30 Oct 2004
Posts: 127

PostPosted: Sat Apr 21, 2007 2:14 pm   
 
Deleted my guildmembers variable, and did #addkey (Talonnb Silverain, Auresian Avenger.) in the command prompt, it made the database record fine.

Same trig on the guild part, but I shortened it to:
The following players from the Daru are online:$(*)$
#echo %1
#echo %iskey( %1, @guildmembers)
#echo %iskey(@guildmembers, %1)

Output again:
Talonnb Silverain, Auresian Avenger.
0
0
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sat Apr 21, 2007 2:23 pm   
 
Hmm, I'm not completely sure if my suggestions are even remotely good, but got another idea.
Change db entry to Player1 in first column and Talonnb Silverain Auresian Avenger in second.

Then, use

Code:


#show %item(%db(@guildmembers,player1),1)



to get the according info out. The point of db variables is that you need to have a key in order to make the search working and in this case player1 is the key.

I don't know tho if thats what you expect.

Prog

EDIT: Sorry btw, I missed writing you about %db command first time. Thats a must part inside a code when you're dealing with dbs.
Reply with quote
talonnb
Apprentice


Joined: 30 Oct 2004
Posts: 127

PostPosted: Sat Apr 21, 2007 2:39 pm   
 
See, the thing is, I want to make a string list of, for example, all the venom hits that are possible with weapons. Then, if I get hit by a weapon, it checks the next line for a valid venom hit, and I'll have the associated numbers trigger to the cure. I just think it would be a good way to do illusion curing and I'm more or less wondering if it's possible....

My Idea:
Trigger - ^Lightning-quick, (%w) jabs your left leg with(*)$(*)$
#if (%ismember( %1, @badtars)) {#var attack1 %ismember(%3, @venomattacks);processattacks}

Kinda like that
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sat Apr 21, 2007 2:56 pm   
 
Huh, I'm pretty confused now what exactly do you want because you're asking a completely different question this time. Anyway, this question seems to be a lot more easier, though.

How exactly does the line when you're touched with venom look like? Is the trigger you're currently providing one possibility or are there several?

Considering the amount of data you're currently giving...

* You make string list for venom types.

* Make a trigger/triggers WHEN you get hit with venom.

* Make the trigger's value to CHECK if the venom is in the list, and if, cure it

I can only suggest the following at this point, though.

Code:


#trigger {^Lightning-quick, %w jabs your {left|right} leg with*({@venomlist})*$} {#if ((%ismember(%1, @venomlist)) {issue cure} {else, attack}}



This is completely untested tho. But it should give you the general idea.


Prog


EDIT: The left|right part. For the sake of having as few triggers as possible (pretty much the way towards I'm going most of the time), you can use the same output for leg as well, I mean, when you get "jabs" to something else than leg. Ie. {leg|arm|head|foot}
Reply with quote
talonnb
Apprentice


Joined: 30 Oct 2004
Posts: 127

PostPosted: Sat Apr 21, 2007 3:16 pm   
 
See, I already have what you suggest.

The code is, for example:

Saybre slashes into you with an ornate steel rapier!
The idea of eating or drinking is suddenly repulsive to you.

Now, I want to do a trigger like:
(%w) slashes into you with an (*)$(*)$
#if (%ismember( %1, @badtars) > 0) {
#if (%ismember( %3, @venomattacks) > 0) {
#if (@attacked = 1) {
#var anorexia 1;PHC
}
}
}
Background, @venomattacks would CONTAIN "The idea of eating or drinking is suddenly repulsive to you." And it would be set to the first location in the variable venomattacks in this case, so %ismember would return 1, attacked would be set to 1, and as a result, anorexia would be set to 1. PHC is my checker that starts the healing, basically ignore that.

I have the whole thing now, where I trigger the The idea of eating or drinking is suddenly repulsive to you. to #var anorexia 1 as normal, but I want it so it REQUIRES that attack phrase to fire it. Hence my wanting to use arrays and matching if possible.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sat Apr 21, 2007 4:53 pm   
 
Ok, arrays would be the proper word to use if you were talking about java C etc languages. In Z/C mud you would call it a string list.

So you make a variable STRING LIST of attacks that could possibly give you this ailment.

ailAttacks=slashes into you with an ornate steel rapier!|throws a dagger at you, it sticks in your chest!|...

And one that is a list of venom patterns.

venomattacks=The idea of eating or drinking is suddenly repulsive to you.|You wonder why there are so many poor people in the world.|You are suddenly afraid of heights.

Then you make a trigger.

{@ailAttacks}$({@venomattacks})

Note that I did not even try to match the name at the beginning of the line. It is unnecessary.

See? Very close to what Progonoi said

Now it would be far easier to do this.

Trigger - ^Lightning-quick, (%w) jabs your left leg with(*)$({@venomattacks})$

But that is up to you.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
talonnb
Apprentice


Joined: 30 Oct 2004
Posts: 127

PostPosted: Sat Apr 21, 2007 6:49 pm   
 
With it searching to see if it matches, and matches fine to say, anorexia, where in the trigger

^Lightning-quick, (%w) jabs your left leg with(*)$({@venomattacks})$

Does it give me the location in the stringlist of the triggered on in like a %1? So I can say, if %1 = 1, #var anorexia 1?
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sat Apr 21, 2007 7:16 pm   
 
Variable part of the trigger gives you whatever string inside the list which matches the pattern. If you write a value for the given trigger, then %1 is the variable so to speak.

If I understand you correctly though, then you want anorexia variable to be set to 1 when venomattacks are seen. Imo there's no need for #if %1 = 1 in there. Not that I can understand what you're supposed to mean with it in the first place. You can use something like that just as easily:

Code:


#TRIGGER {^Lightning-quick, (%w) jabs your left leg with(*)$({@venomattacks})$} {#if ((%ismember(%1,@venomattacks)) {anorexia=1;do all that other stuff you're doing} {anorexia=0;do all that stuff you're doing when venom attacks are not seen}}




Prog
Reply with quote
talonnb
Apprentice


Joined: 30 Oct 2004
Posts: 127

PostPosted: Sat Apr 21, 2007 7:28 pm   
 
But if you'll note in my top example, the first of this thread, that I tried %ismember, and for some reason, even if the items are in the stringlist as what is matched, %ismember always seems to return 0......Hence my confusion
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sat Apr 21, 2007 7:49 pm   
 
OK.

Gave it a shot and tested it myself now. Following SHOULD work.

Code:


#trigger {^Lightning-quick, %w jabs your left leg with*({@venomattacks})$} {#if ((%ismember( %1, @venomattacks))) {anorexia=1;#say Works! Cure me!} {#say Doesn't Work! That is unknown venom, maybe not even bad for me?!}}



Prog
Reply with quote
talonnb
Apprentice


Joined: 30 Oct 2004
Posts: 127

PostPosted: Sat Apr 21, 2007 7:54 pm   
 
Wierdly enough, I wrote a new one, duplicated exactly what I did before and it works now.....go figure.

Thanks for the help guys, appreciated.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sat Apr 21, 2007 9:07 pm   
 
I had not really paid much attention to how you did this. To answer your question.
Quote:
The following players from the Daru are online:$(*)$(*)$(*)$ - Trigger
#echo %1
#echo %2
#echo %3
#echo %ismember( %1, @guildmembers)
#echo %ismember( %2, @guildmembers)
#echo %ismember( %3, @guildmembers)

What I get as an output:
Master Miran, Seeker of Purity.
Purifying Flame, Grand Master Kylan, fio Naecelm Ciehianari.
Talonnb Silverain, Auresian Avenger.
0
0
0


Your values are being stored in the % variables because you are using ().
So...
%1=Master Miran, Seeker of Purity.
%2=Purifying Flame, Grand Master Kylan, fio Naecelm Ciehianari.
%3=Talonnb Silverain, Auresian Avenger.

Obviously Master Miran, seeker of Purity does Is not the same thing as Miran. So ismember would correctly tell you that "Master Miran, seeker of Purity" is not in the list. Even though Miran IS.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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