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: Fri May 22, 2015 12:12 am   

Random Direction Trigger not triggering everytime.
 
So I tried writing a script that will move me in a random direction within the possibilities of the room I'm in. I don't want to go back the direction I came, so I remove that direction from the possibilities. And there are certain bounds that I need to stay within so I don't die a quick death...

The script works just fine sometimes.. However, it's not uncommon for it execute, and not actually imput any directional command. Then when it fires again, it might or might not work, however, /always/ on the 3rd time it'll work. A lot of the time it does work on the first try though. I'm not sure what's causing the delay. I have put in there twice because i thought maybe the "random" code was taking too long or something. It's code I wrote years ago though.. So i'm not sure why I have some of it in there.

The "find" command in there is to find the room i'm currently in and to make sure the map is up to date so I know which directions are possible exits.

Would anyone mind cleaning it up a bit? Possibly with some cleanup, I can get it to consistently fire.
Let me know if you need anything more to look into it!

Thanks!



Room output:

A Treacherous Slope
Two large hills towers up to the east and west, and another one not far to
the south. They are one of the hillier areas of the Blasted Lands. The heat
is not as unbearable here, in this small valley between the hills as it is
on most of the tops, yet it is dangerous to stay in the sun too long. The
shade of a dead tree may well prove lifesaving in this heat and drought.
[ obvious exits: N E W ]


Direction List: n|s|e|w|u|d

#ALIAS gonextroom

#VAR goingroomexit %roomexit( )
#VAR roomoptions %numitems( @goingroomexit)
#IF (@roomoptions>1) {
#MATH roomoptions @roomoptions-1
#VAR goingroomexit %delItem( @removethisdir, @goingroomexit)
}
#VAR randomdir {%item( @goingroomexit, %random( @roomoptions))}
#IF (%ismember( @randomdir, @directionlist)) {
#IF (%mapvnum=1668) {
#VAR randomdir s
#ECHO Staying In Bounds
}
#IF (%mapvnum=1658) {
#VAR randomdir s
#ECHO Staying In Bounds
}
#IF (%mapvnum=1710) {
#VAR randomdir w
#ECHO Staying In Bounds
}
#IF (%roomname=(Coach Stop at the Peak of the Erinin Bridge)) {
#VAR randomdir w
#ECHO Staying In Bounds
}
#IF (%roomname=(Knee Deep in the Muck)) {
#VAR randomdir e
#ECHO Staying In Bounds
}
#IF (%roomname=(A Crude Stone Well)) {
#VAR randomdir n
#ECHO Staying In Bounds
}
#IF (%roomname=(Coastal Road Through the Swamplands)) {
#VAR randomdir e
#ECHO Staying In Bounds
}
#WAIT 1000
@randomdir
#VAR olddirectiongone @randomdir
#WAIT 1000
find
} {
#VAR randomdir {%item( @goingroomexit, %random( @roomoptions))}
#IF (%ismember( @randomdir, @directionlist)) {
#STATE killagaincondition 0
#IF (%mapvnum=1668) {
#VAR randomdir s
#ECHO Staying In Bounds
}
#IF (%mapvnum=1658) {
#VAR randomdir s
#ECHO Staying In Bounds
}
#IF (%mapvnum=1710) {
#VAR randomdir w
#ECHO Staying In Bounds
}
#IF (%roomname=(Coach Stop at the Peak of the Erinin Bridge)) {
#VAR randomdir w
#ECHO Staying In Bounds
}
#IF (%roomname=(Knee Deep in the Muck)) {
#VAR randomdir e
#ECHO Staying In Bounds
}
#IF (%roomname=(A Crude Stone Well)) {
#VAR randomdir n
#ECHO Staying In Bounds
}
#IF (%roomname=(Coastal Road Through the Swamplands)) {
#VAR randomdir e
#ECHO Staying In Bounds
}
#WAIT 1000
#IF (@engaged == 0) {@randomdir}
#WAIT 1000
#ECHO It happened twice
}
}
#IF (@randomdir=w) {#VAR removethisdir e}
#IF (@randomdir=e) {#VAR removethisdir w}
#IF (@randomdir=s) {#VAR removethisdir n}
#IF (@randomdir=n) {#VAR removethisdir s}
#IF (@randomdir=u) {#VAR removethisdir d}
#IF (@randomdir=d) {#VAR removethisdir u}
#WAIT 100 killagain "Scripts|Statting"
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri May 22, 2015 4:36 am   
 
The biggest potential problem I see is your use of #WAIT. As a general rule #WAIT is bad. You should design your script to complete with variables recorded and a direction sent. Use a trigger on the line '[obvious exits:' to activate your script again.

It would appear that you duplicate an entire section of the script. Your script has "#IF (%ismember( @randomdir, @directionlist)) {" then in the else section of the #IF you repeat everything in true section and even have a second "#IF (%ismember( @randomdir, @directionlist)) { " this does not make sense to me. About all I can guess is that you want it to pick a direction again to ensure that the selected direction is in @directionlist. If that was your intent then you should cull the @goingroomexit list for anything not in the @directionlist before picking a random direction; make sure you have a fall back for an empty list.

All your 'staying in bounds' tests specifically set the @randomdir and are mutually exclusive. They should be done before using the random function to set that variable and should prevent subsequent resetting using an if..else chain, for example:
Code:
#IF (condtion) {
 do something
} {
 #IF (next condition) {
  do another something
 } {
  default do something
 }
}

I would suggest changing lines like
Code:
#IF (%roomname=(A Crude Stone Well)) {
to
#IF (%roomname="A Crude Stone Well") {
Placing string values in quotes is proper; zMud is quite forgiving but using the proper method ensures consistent results.

You might also change this section
Code:
#VAR roomoptions %numitems( @goingroomexit)
#IF (@roomoptions>1) {
#MATH roomoptions @roomoptions-1
#VAR goingroomexit %delItem( @removethisdir, @goingroomexit)
}
#VAR randomdir {%item( @goingroomexit, %random( @roomoptions))}

to

#VAR goingroomexit %delItem( @removethisdir, @goingroomexit)
#IF (@goingroomexit="") {
 #VAR randomdir {@removethisdir}
} {
 #VAR roomoptions {%numitems( @goingroomexit)}
 #VAR randomdir {%item( @goingroomexit, %random( @roomoptions))}
}
_________________
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: Fri May 22, 2015 5:29 am   
 
Thank you very much for your response.

I use the #wait because I wanted to give time for everything to function. When I think about it now, I guess it all happens pretty quick, so I could do away with it. I'll give that a shot. I think that's the same reason I made basically duplicate of the entire section because if the first one didn't work, the second one would sometimes. Actually most the time, if the first one triggered, but no direction was entered, it would do it again, and I'd get the "It happened twice" thing. I put that in there because sometimes the trigger would trigger but no direction would be entered, and it'd have to loop again before it did it. And I don't know why. Which is why i'm asking for help.

My exit directions are always within the @directionlist. The mud only has those 6 directions. So I don't actually need that if statement. Because they can't be anything else. So I think I'll take that out and re-write it without that.

Can you explain what you mean by the "staying in bounds" are mutually exclusive? Can you explain what you mean and where you would have those put in? Would it be something like.

Look for exits:
If room is *. Remove *
then ramdomize?

On this part:

#IF (@goingroomexit="") {
#VAR randomdir {@removethisdir}
}

Is this to take care of the >1 part? It seems really clever. :) Thanks for that bit. It avoids the #Math part. So basically, if I've already removed the only exit, it goes the way I wanted to remove in the first place.


I am definitely going to rewrite it with some of the newer understanding i have on coding. I am a serious armature when it comes to coding, infact, zmud is the only thing I code. and poorly at that.

So, any idea why it will sometimes not put a direction in? I know that's a long shot without testing, and I'll test more tonight and come back with a rewritten script for you to pick apart, but, if you have any idea, let me know.

Thanks again for your response! I bought zmud, and writing little scripts has been at least as fun if not more than actual mudding!

Thanks!
Reply with quote
MisterDwooD
Novice


Joined: 04 Feb 2014
Posts: 42

PostPosted: Fri May 22, 2015 6:57 am   
 
I'm sorry that this is so convoluted! I don't know how else to be sometimes. (Thank you Vijilante for your help, i did use some of your examples in my revamp!)

So... I am still having some difficulties. I have split the setup into 2 different scripts. A trigger, and an Alias.

Here is the Trigger:

#TRIGGER ~[ obvious

Code:
#VAR goingroomexitds %roomexit( )
#VAR goingroomexitds %delItem( @removethisdirds, @goingroomexitds)
#IF (@goingroomexitds="") {#VAR randomdirds {@removethisdirds}} {
  #VAR roomoptionsds {%numitems( @goingroomexitds)}
  #VAR randomdirds {%item( @goingroomexitds, %random( @roomoptionsds))}
  }
#IF (@randomdirds="") {} {}


Here is the Alias:

gonextroom

Code:
 #IF (%roomname=(Burbling Mudpits)) {
  #VAR randomdirds s
  #ECHO Staying In Bounds
  }
 #IF (%roomname=(In Front of the Castle)) {
  #VAR randomdirds n
  #ECHO Staying In Bounds
  }
 #IF (%roomname=(Rotten Vegetation)) {
  #VAR randomdirds n
  #ECHO Staying In Bounds
  }
 #IF (%roomname=(Below the Dark Column)) {
  #VAR randomdirds w
  #ECHO Staying In Bounds
  }
 #IF (%roomname=(Valley Floor)) {
  #VAR randomdirds w
  #ECHO Staying In Bounds
  }
 #IF (%roomname=(Above a Dark Hole)) {
  #VAR randomdirds s
  #ECHO Staying In Bounds
  }
 #IF (@engaged == 0) {
  @randomdirds
  #IF (@randomdirds="") {
    #ECHO tried to move but no dir to move
    #ECHO goingroomexitds @goingroomexitds
    #ECHO removethisdirds @removethisdirds
    #ECHO roomoptionsds @roomoptionsds
    #ECHO randomdirds @randomdirds
    }
  }
 #WAIT 1000
 find
#WAIT 100 killagainds
 #IF (@randomdirds=w) {#VAR removethisdirds e}
 #IF (@randomdirds=e) {#VAR removethisdirds w}
 #IF (@randomdirds=s) {#VAR removethisdirds n}
 #IF (@randomdirds=n) {#VAR removethisdirds s}
 #IF (@randomdirds=u) {#VAR removethisdirds d}
 #IF (@randomdirds=d) {#VAR removethisdirds u}



Here is my output when it's failing. It doesn't always fail, but it still does sometimes, and I have no idea why. If you look at the variables that I have it spitting out, there should be no reason why it didn't get the random direction to move.

Dank Swamp
Dead leaves and old branches spread all across the ground here have been
infected with the foul mud that fills this swamp. The decomposing material
sends out a horrible smell that forms a sort of mist, hanging over the rotting
swamp. The ground underfoot is soggy and barely walkable. Standing still would
make you sink. The muddy ground stretches out north, east and south, and
drier ground extends to the west.
[ obvious exits: N E S ]
Matching room found! Correcting map position.

o HP:Healthy MV:Tiring > kill 2.leatherleaf
They aren't here.
kill deer

o HP:Healthy MV:Tiring > They aren't here.
kill stick

o HP:Healthy MV:Tiring > They aren't here.

tried to move but no dir to move
goingroomexitds e|n
removethisdirds s
roomoptionsds 2
randomdirds


o HP:Healthy MV:Tiring >

___________________________

Another example:

look
Finding yo Room.
Blasted Lands
Barren hills stretch in all directions. Boulders lie strewn upon them, and
sharp outcroppings of dark stone jut out in many places. To the south, it
seems that many of the boulders have been cleared to form a trail. To the
north stands a tall hill, blackened by some unknown flame.
[ obvious exits: N E S W ]
Matching room found! Correcting map position.
A grime-covered weary trolloc goes about his duties, eyes on the ground.

* HP:Healthy MV:Strong > kill 2.leatherleaf
They aren't here.
kill deer

* HP:Healthy MV:Strong > They aren't here.
kill stick

* HP:Healthy MV:Strong > They aren't here.

tried to move but no dir to move
goingroomexitds n|e|w
removethisdirds s
roomoptionsds 3
randomdirds

* HP:Healthy MV:Strong >



What's happening is it will execute the trigger. But, there's nothing in the random direction field, and so it doesn't do anything. I have no idea why it sometimes works and why it sometimes doesn't. If it doesn't work the first time, I have it set to just do it again after reloading the room and it works.

What I'm thinking maybe to do, since i can't find out why it doesn't work, maybe just run the "random" command until it does work. Is there anyway to make it so that after it runs the trigger to #loop it until the "randomdir" has a direction" something like:

Code:
#IF (@randomdirds="") {#LOOP} {}


But have it loop that entire trigger until @randomdirds=something

The issue doesn't appear to be in the alias, but rather in the trigger. It's like it's running through the trigger commands, but it finishes one before something else, so it breaks it or something.

Let me know if you have any other questions. I also have another super difficult issue, and would be happy to talk compensation if anyone wanted to troubleshoot/teach me how to resolve it. If that's against the rules, then i'm NOT happy about it. :)

Anyways. Thanks again for your help guys!
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat May 23, 2015 12:11 pm   
 
Let me start by again saying that; while zMud is forgiving, using the proper syntax will yield consistent results. The correct format is to enclose string portions in double quotes.
Code:
WRONG #IF (%roomname=(Above a Dark Hole)) {  WRONG
RIGHT  #IF (%roomname="Above a Dark Hole") { RIGHT


Mutually exclusive means that when thing 1 is true no other thing can be true, and that when the thing 2 is true no other thing can be true, and that when thing 3 is true not other thing can be true, etc. Obviously when roomname="Burbling Mudpits" it would be impossible for roomname to be equal to "In Front of the Castle", "Rotten Vegetation", "Below the Dark Column", "Valley Floor", or "Above a Dark Hole". The same is true for each of those potential options, and that is what is mutually exclusive...each one excludes the others. See my first post about how to make use of that fact.

You still have #WAITs, and zMud is horrible for #WAIT. CMud corrected many of the issues with #WAIT. I would strongly suggest thing about how to eliminate them from your scripts. Think about what it is you really want the script to wait for and then build the script in pieces so that it waits on the correct signals.

You have provided no indication of how the alias becomes executed. I can not possibly debug code I have no knowledge of. By all appearances, you have a trigger that activates on the "They aren't here" to run through a series of attacks, and then activate the alias to move on, it seems to be right and working correctly.

I have no clue where the @engaged variable is set or cleared. I can't debug that which I have no knowledge of.

Since you are using the mapper I also have to note that timing can be tricky. Your "#TRIGGER ~[obvious" seeks to grab information from the mapper. If the mapper settings cause the location update to occur later than the triggering line then the information will be inaccurate. I would suggest you use an alias named "onroomenter" to get information after the mapper has updated to being in a new room.
_________________
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: Sun May 24, 2015 5:18 am   
 
Man, it seems like you're a little bit upset with me. I am sorry. I'm just trying to learn here.

I think this might be interesting for you to see, and i'm not asking for you to fix it, cause it works for me.. whether it's right or not.

I have a trigger that fires on the "Obvious Exits" part of the room. It runs an alias: failsafemovels. This is the code in it:

Code:
#ECHO removethisdir @removethisdir
#VAR goingroomexit %roomexit( )
#ECHO goingroomexit @goingroomexit
#VAR goingroomexit %delItem( @removethisdir, @goingroomexit)
#ECHO goingroomexit @goingroomexit
#IF (@goingroomexit="") {#VAR randomdir {@removethisdir}} {
  #VAR roomoptions {%numitems( @goingroomexit)}
  #ECHO roomoptions @roomoptions
  #VAR randomdir {%item( @goingroomexit, %random( @roomoptions))}
  }
#ECHO randomdir @randomdir
#IF (@randomdir="") {failsafemovels} {}


I have it echoing everything until it actually finds a "randomdir".
In the example below, it ran it 6 times before it actually found a "randomdir". I was already in the room. infact, it knows it's options as you can see it listing them before it chooses the room.

look
Finding yo Room.
The Western Foot of the Erinin Bridge
Just eastward, the Erinin flows under a large stone bridge, its waters rapidly
heading into the south, gently curving around the city of Tear before the
Fingers of the Dragon. While cracked and weathered, the stone bridge appears
quite sturdy, and is wide enough for two wagon teams to pass side-by-side.
[ obvious exits: E W ]
Matching room found! Correcting map position.
removethisdir e
goingroomexit e|w
goingroomexit w
roomoptions 1
randomdir
removethisdir e
goingroomexit e|w
goingroomexit w
roomoptions 1
randomdir
removethisdir e
goingroomexit e|w
goingroomexit w
roomoptions 1
randomdir
removethisdir e
goingroomexit e|w
goingroomexit w
roomoptions 1
randomdir
removethisdir e
goingroomexit e|w
goingroomexit w
roomoptions 1
randomdir
removethisdir e
goingroomexit e|w
goingroomexit w
roomoptions 1
randomdir w
An arrogant bridgeguard sneers haughtily at you, riding a |1|.black stallion.
An arrogant bridgeguard sneers haughtily at you, riding a |2|.black stallion.
An arrogant bridgeguard sneers haughtily at you, riding a |3|.black stallion.

* HP:Healthy SP:Bursting MV:Winded >

Anyways. Just thought I'd let you know. I think %random is something weird.

I did fix the "string portions". I really did listen, and they were fixed, just not before I copied the new script.
I do know what "mutually exclusive" means.. I just didn't know what you meant by your example on how to implement it.
Now i think i do know what you meant. If it's 1 room, do something, if not, check to see if it's another room, do something if is, and if not check to see if it's another room. and if it's not any of those rooms. Just do the last thing, which is find a random direction. And i've implemented that. So Thank You for that. it helped a bunch.

I do still have #waits. But if I don't. things happen VERY fast. i need it to slow down a bit. You only have certain "moves" in the mud I play, and if you go too fast, you'll burn em all before regenerating some. So a second here, and a second there, I'm okay with the #wait sometimes. I have replaced some with #alarm just to remove MOST of them.
---------Correction. I now have ZERO waits in the script. thank you for the motivation to do that.

I still have another big quandry, and I'll post it. though, i think i'll use some videos to try and show what I'm getting at, cause it's stupid annoying and hard to find out what's going on.

Thanks again for your feedback.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun May 24, 2015 12:10 pm   
 
I apologize for tone in my last post; I probably was dealing with a couple of fools in another venue and let my frustration with them bleed through everything.

Let us look at the help for %random. We can see that when you do not specify both the minimum and maximum values the range is [0..specified value]. Probability says that while thousands of flips of a coin. when aggregated. will tend towards being equal for heads and tails; smaller subsets may have a strong bias towards either head or tails. Next we can look at %item; and we will see that function expects its numbering to start at 1, giving 0 as an item number to %item will always result in a null string. It would appear that you hit a pocket of 0's then a 1.

Perhaps I should have noticed and corrected it in your original script, but I didn't. You need to change all your uses of %random to include a minimum of 1 in regard to this script.

Using #ALARMs will make a solid difference. You can turn them on and off with #T+ and #T- if you have named them. Also you can use them as a sub-state to a trigger which works like automatically turning the alarm on and off.
_________________
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: Mon May 25, 2015 5:58 am   
 
Thank you for the response. Maybe it is calculating from thousands of options. So, how do we change that? Using my script, how would you do that? I don't know how to put a minimum of "1" since i'm using using numeric options.. rather, single letter options.

Thanks.
Reply with quote
shalimar
GURU


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

PostPosted: Mon May 25, 2015 7:39 am   
 
%random(1, @roomoptions)
_________________
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34
Reply with quote
MisterDwooD
Novice


Joined: 04 Feb 2014
Posts: 42

PostPosted: Mon May 25, 2015 11:46 am   
 
Well, that did it. :)

So I have re-written like 90% of my script with what we've talked about. but, the initial question was "Random Direction Not Triggering Everytime"... And that did it.

Giving the %random a min limit has made it so it doesn't ever call 0, which was what was happening.

It's now firing 100% of the time with a direction.

Thank You sir. That indeed makes me happy! :) I can at least count on that happening all the time, and can work with at. I'm so happy! :) Thanks!
Reply with quote
Dasyr
Newbie


Joined: 29 Jan 2016
Posts: 8

PostPosted: Fri Jan 29, 2016 6:54 pm   
 
Not sure if this helps at all but here's a random move script I wrote;

Code:
#class {Move}
#class {Move|Triggers}
#trigger {~[ Exits: (*) ~]} {#variable exits %replace(%1," ",|);#wa 1000;#if {@moveallowed=1} {domove}}
#trigger {You (%w) (%w).} {#variable moving 1;#variable exits {};#if {%2=north} {#variable entered S};#if {%2=south} {#variable entered N};#if {%2=east} {#variable entered W};#if {%2=west} {#variable entered E};#if {%2=down} {#variable entered U};#if {%2=up} {#variable entered D}}
#class {Move|Alias}
#alias domove {#variable moveex %item(@exits,%random(1,%numitems(@exits)));#if {%item(@exits,2)=""} {@moveex} {#if {@moveex!=@entered} {@moveex} {domove}}}
#class {Move|Variables}
#variable moveallowed {1} {0}
#variable ismoving {0} {0}
#variable moveex {} {}
#variable exits {} {}
#variable entered {} {}
#class 0
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