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
MisterDwooD
Novice


Joined: 04 Feb 2014
Posts: 42

PostPosted: Thu Feb 04, 2016 12:46 am   

Variable Contains Script
 
I'm looking for a way to look at a variable, and see if somewhere int he variable it contains a certain string. For example:

Script to trigger on:

|wielded| a strong-arms club

Trigger:

#trig {~|wielded~| (*)} {#VAR yougotsomeweapon %-1;#ECHO @yougotsomeweapon}

For some reason, I can't get the whole weapon string in. It only captains the "a"...

But, the main things is: How do I do this:

#if %contains(@yougotsomeweapon, club) {#var thisisyourweapon club}

Does that make sense? I want it to trigger off my wielded weapon, and then put it in a variable. If i don't need to create the @yougotsomeweapon to check, then maybe only needs to be one step.. like:

#trig {~|wielded~| (*)} {#if %contains(%1, club) {#var thisisyourweapon club} }}



note. this is all freehand and not actual scripts.. Just for random example.

Thanks!
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Thu Feb 04, 2016 1:27 am   
 
%pos("club", %1)
Reply with quote
MisterDwooD
Novice


Joined: 04 Feb 2014
Posts: 42

PostPosted: Thu Feb 04, 2016 5:02 am   
 
Thanks for posting. But that's not really what i'm looking for. For example.

Mud output:

|wielded| a strong-arms club

Trigger:


PostPosted: Wed Feb 03, 2016 5:46 pm

Variable Contains Script

I'm looking for a way to look at a variable, and see if somewhere int he variable it contains a certain string. For example:

Script to trigger on:

|wielded| a strong-arms club

Trigger:

#trig {~|wielded~| (*)} {#var yougotsomeweapon %1
#if %contains {@yougotsomeweapon, dagger} {#var wieldedweapon dagger}
#if %contains {@yougotsomeweapon, sword} {#var wieldedweapon sword}
#if %contains {@yougotsomeweapon, mace} {#var wieldedweapon mace}
#if %contains {@yougotsomeweapon, axe} {#var wieldedweapon axe}

That way I don't have to manually set my wielded weapon.

Does that make sense?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Feb 04, 2016 6:49 am   
 
Work smarter not harder
Code:
#TRIGGER {~|wielded~| *({dagger|sword|mace|axe})} {#VAR wieldedweapon {%1}}


Work harder version
Code:
#TRIGGER {~|wielded~| (*)} {#VAR yougotsomeweapon {%1}
#IF (%pos ("dagger", @yougotsomeweapon)) {#VAR wieldedweapon {dagger}}
#IF (%pos ("sword", @yougotsomeweapon)) {#VAR wieldedweapon {sword}}
#IF (%pos ("mace", @yougotsomeweapon)) {#VAR wieldedweapon {mace}}
#IF (%pos ("axe", @yougotsomeweapon)) {#VAR wieldedweapon {axe}}}


Proper use of delimeters such as () {} "" can never be stressed enough. zMud is forgiving about doing it wrong, but can't always guess what you mean when using strange combination.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
MisterDwooD
Novice


Joined: 04 Feb 2014
Posts: 42

PostPosted: Sat Feb 06, 2016 3:57 am   
 
Thanks guys for piping in.

I've never used the %pos command before. Can you give me a quick rundown of it? Or rather, just confirm if my understanding is correct.. Usually it's what position is *blah* in @blah. So, using it in the way you did just checks to see if *blah* is anywhere in @blah?

If so, that's genius. Another question:

Why do you have ({dagger|sword|mace|axe}) inside brackets and parenthesis?

Thanks!
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sat Feb 06, 2016 4:53 am   
 
"Thanks guys for piping in.

I've never used the %pos command before. Can you give me a quick rundown of it? Or rather, just confirm if my understanding is correct.. Usually it's what position is *blah* in @blah. So, using it in the way you did just checks to see if *blah* is anywhere in @blah? "

In my initial post when I first suggested it, I included a link to the documentation on %pos. But yes, it works exactly like what you were describing. It's just called %pos, not %contains.

"Why do you have ({dagger|sword|mace|axe}) inside brackets and parenthesis?"

The braces denote a list, so that trigger pattern will match any of those words. The parentheses create a capture group, so the match can then be referenced as %1, %2, etc (same as your "(*)").
Reply with quote
MisterDwooD
Novice


Joined: 04 Feb 2014
Posts: 42

PostPosted: Sat Feb 06, 2016 6:32 pm   
 
That is exactly what I needed to learn! You guys were both a great help! It's working swimmingly now!
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