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
zBob
Beginner


Joined: 21 Feb 2011
Posts: 12

PostPosted: Mon Feb 21, 2011 6:22 am   

reference a trigger's id from within the trigger
 
Is there a way to reference a trigger's ID from within the trigger?

As a cheesy example:

#SAY Trigger %TriggerID just fired.

(There is no predefined function called %TriggerID, but maybe there's something similar and THAT is what I'm searching for :-) )
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Feb 21, 2011 11:06 pm   
 
#say Trigger TriggerID just fired.

Just change what's in bold to what the real id is. The #SAY is already in the trigger, so there's no need for any function to expose the ID.
_________________
EDIT: I didn't like my old signature
Reply with quote
zBob
Beginner


Joined: 21 Feb 2011
Posts: 12

PostPosted: Mon Feb 21, 2011 11:20 pm   
 
Hardcoding the ID of the trigger into the body of the trigger's just what I'm trying to avoid.
In what I'm doing that'd have me repeating the trigger id in 3 places per trigger in a set of about 100 triggers.
I can do it, but it'd be more elegant if I could just have it in one place.

Surely the trigger id is exposed via a function or via some sort of instance or env variable?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Feb 21, 2011 11:24 pm   
 
That's a lot of triggers. Are you certain you need all of them? There's no way to consolidate them at all? No, the trigger id is not exposed by a function.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Feb 22, 2011 6:19 pm   
 
There currently isn't any way for your script to know what trigger it is being fired from. But that's an interesting idea for the future, so I'll add it to the wish list.

However, in the mean time, you might want to post more about what you are trying to do with your triggers because there might be a better way to solve the problem that doesn't involve needing to know the trigger id value.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4701
Location: Pensacola, FL, USA

PostPosted: Tue Feb 22, 2011 7:24 pm   
 
Zugg... might i suggest %this as the new function name?
I know its used in other programming languages for similar referencing.
_________________
Discord: Shalimarwildcat
Reply with quote
zBob
Beginner


Joined: 21 Feb 2011
Posts: 12

PostPosted: Thu Feb 24, 2011 9:43 pm   
 
It's a little complicated which is why I didn't offer up the details originally, but since you asked :-)

I'm going through the Lua tutorial in the Help in my spare time (what a fun read too by the way!) because I hope there's something in that which will let me address the trigger's properties.

The triggers are for knowing when I've started and finished each of about 100 spells.

There's a few useful things I can do when I know a spell has started or finished.

The most useful thing is something of a queue system.
Cast this, then this, then this. ... well, eventually. Right now the queue has a max-length of 1.
Having my character able to handle the next few min of easy combat on his own makes it it possible for me to get a few other things done at the same time - like write more cMud triggers :-)

Each spell has a few different starting and ending phrases.
Cast the same spell and it might start off as "You raise your wand" or "Energy crackles through your wand" or "The orc flinches as you point your wand at her".
And likewise the ending of each of these spells can have a few endings like "Lightning issues forth from your wand" or "The orc is blasted from her feet by the bolt of lightning".

So right now I've got a multi-state trigger for each of 20-30 of the spells.
The main trigger-text is for each is a regex that includes all of the possible openings of the spell.
The next stage of the trigger is a regex matching the ending possibilities.
I love the multi-state triggers because it makes it so much cleaner.

The actual script of each trigger is nearly identical:

For the opening, first state of each trigger:
alias-spell-started "<spellname>"
(ie: alias-spell-started "lightning bolt")

For the ending, second state of each trigger:
alias-spell-done "<spellname>"

"alias-spell-started" and "alias-spell-ended" are of course cMud aliases that are used by all these triggers.
They're the things that process the queue.

I find it very helpful for those aliases to know what trigger called them, so now I'm hard-coding the spell name into the script of each trigger like shown above. I'd rather that be the trigger-id so that I just keep it in one place.
Especially since I'm already filling out the trigger-id field because that's the only way I can keep up with all of the triggers.
If I'm looking to add a new starting-string to the trigger for "lightning bolt" I can't easily find that trigger otherwise because cMud only shows the trigger-text, not first line of the script body like zMud used to. And the spell name isn't part of the opening-text of the spell, so if I don't put fill in the trigger-id I have to click on each of the (eventually 100+) triggers and read the script body to find which spell it goes to.

Thanks for all the thoughtful replies :-)
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Feb 24, 2011 10:48 pm   
 
Did you know that aliases (as well as functions and events) can be passed arguments? Since you have a many-on-one situation going on, and since each trigger is exclusive to an individual spell, you can just modify your aliases to check for parameters.
_________________
EDIT: I didn't like my old signature
Reply with quote
zBob
Beginner


Joined: 21 Feb 2011
Posts: 12

PostPosted: Fri Feb 25, 2011 2:50 pm   
 
Yah - that's what's already going on.

What I mean by:

alias-spell-done "<spellname>"

is that the cMud alias is named "alias-spell-done" and it's being passed the parameter "<spellname>"

And that "<spellname>" is hard coded in each alias.
I was hoping to find a way to pass the trigger ID instead of hard-coding it.

I'm considering changing all these individual-spell triggers from calling those specific aliases to raising events, but I'm not sure about that.
I don't know how well cMud would work with an extra 200 events added in (100 start-spell events and 100 end-spell events).
And then instead of two aliases handling all of these, I'd need 200 on-event triggers.

.... or maybe it wouldn't be quite that heavy. I think I remember reading that events can have parameters, so maybe just 2 events:
start-spell <spellname>
and
end-spell <spellname>

I'd still need to hardcode either the spell-specific event raisings or the spell-name parameters into each trigger and into each 2nd-stage of the trigger.

There's an eleganter solution around here, I just know it and I'll find it :-)
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Fri Feb 25, 2011 8:58 pm   
 
First you can press CTRL+F with the Package Editor open to search through your settings for a certain command, function, or some random text. So there is no need to look through each setting one by one to find what you want.

Have you considered streamlining your system to something like I have below? It uses one multi-state trigger with two states, two DB variables and should be able to do everything you are doing with the tons of triggers you have now. The spell start messages you gave sounded rather generic but if they are unique to each spell then you can add the spell name into the value field for each key it's paired with like I have done. Then you add the finish message as the key and the spell name as the value in the done variable.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <class name="SpellQue" copy="yes">
    <var name="SpellStartedMessages" type="Record" sorted="1" copy="yes">
      <value>Energy crackles through your wand=Lightning bolt|The orc flinches as you point your wand at her=Lightning bolt|You raise your wand=Lightning bolt</value>
      <json>{"Energy crackles through your wand":"Lightning bolt","The orc flinches as you point your wand at her":"Lightning bolt","You raise your wand":"Lightning bolt"}</json>
    </var>
    <var name="SpellDoneMessages" type="Record" sorted="1" copy="yes">
      <value>Lightning issues forth from your wand=Lightning bolt|The orc is blasted from her feet by the bolt of lightning=Lightning bolt</value>
      <json>{"Lightning issues forth from your wand":"Lightning bolt","The orc is blasted from her feet by the bolt of lightning":"Lightning bolt"}</json>
    </var>
    <trigger name="Spells" priority="50" copy="yes">
      <pattern>^({@SpellStartedMessages})</pattern>
      <value>alias-spell-started %db(@SpellStartedMessages,%1)
</value>
      <trigger>
        <pattern>^({@SpellDoneMessages})</pattern>
        <value>$value = %db(@SpellDoneMessages,%1)
alias-spell-done $value
</value>
      </trigger>
    </trigger>
  </class>
</cmud>


Like MattLofton said you can have things like aliases, functions, and events work with the parameters you pass to them. Take your alias-spell-done alias for example. You could do something like the code below and check the spell name param you pass the alias from the above triggers and do things on a per spell basis.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="alias-spell-done" copy="yes">
    <value>#switch (%-1 = "Lightning bolt") {#print Lightning bolt was cast successfully.}
  (%-1 = "Anoter Spell") {#print Another spell was cast successfully.}</value>
  </alias>
</cmud>


Regardless of what you use as a reference, be it the trigger ID or the spell name, the end result should be the same. The script is going to perform the action(s), that you told it to do in the code. As long as it knows what to do when everything should be fine.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
zBob
Beginner


Joined: 21 Feb 2011
Posts: 12

PostPosted: Sat Mar 05, 2011 9:06 pm   timing events
 
I'm trying to figure out how long certain things in my mud take.

The way I'm thinking of doing it is by noting the start time and end in internal format, getting the difference, and displaying the difference in minutes and seconds.

But I'm having trouble finding a function that will convert a time to an internal format.
Is there a function for that in zScript?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Sat Mar 05, 2011 9:16 pm   
 
You should create a new thread for a new topic, rather than reusing an old thread.

No, there are no functions to convert time formats, or to do math on times or dates. Basically, you would have to write functions yourself.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Mar 05, 2011 9:30 pm   
 
There is no function for what you're asking for. You need to write it yourself or find one written by some other player. Remember, zScript (or LUA, Javascript, VBscript, etc) are scripting languages and are intended to provide only basic building blocks to let you build more advanced extensions (functions, etc).
_________________
EDIT: I didn't like my old signature
Reply with quote
zBob
Beginner


Joined: 21 Feb 2011
Posts: 12

PostPosted: Sun Mar 06, 2011 2:46 am   
 
Egads! My bad! I thought I was creating a new thread!

I've created a new one just now, though I think I have my answer: zScript doesn't include such a function.

The new thread is here:
http://forums.zuggsoft.com/forums/viewtopic.php?p=165060#165060

Sorry about hijacking my own thread!
Reply with quote
zBob
Beginner


Joined: 21 Feb 2011
Posts: 12

PostPosted: Sun Mar 06, 2011 10:42 pm   
 
Thanks again for the responses.
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