Auto reroller sends one extra unwanted repeat of command

Posted by Wraithian on Sat 08 Nov 2003 10:22 PM — 7 posts, 27,131 views.

USA #0
Ok. I'm currently playing a WoT based mud that lets you "roll" for stats. I made me a trigger/variable/script combo to help me get the perfect stats.... I have a small problem in it, however, that makes my trigger useless.

Here is the problem: The trigger and script will happily reroll the stats till it finds the ones I want. When it does find it, the script does stop. However, I find that it stops one revolution too late: in other words, it stops right after it sends an extra "n" to the mud.
Here is the trigger/variable/script info:

Stat Triggers:
  • Label: trgStatCon/trgStatInt/trgStatWis (to match the purpose of each stat trigger)
  • Trigger text: constitution/intelligence/wisdom : %1
  • Action: Sends the %1 value of each trigger to its corresponding variable: varStatCon, varStatInt and varStatWis
  • Sequence: 90 for all three triggers.


Prompt trigger:
  • Label: trgStatCheck
  • Trigger text: Do you wish keep these stats? *
  • Action: call script ScriptStatCheck
  • Sequence: 100 (hopefully forcing this trigger to let the others fire first)

    Script Code:
    Sub ScriptStatCheck (trgStatCheck, theoutput, Wildcards)
    dim iCon, iInt, iWis
    
    'Assign each script variable the value of its matching mud variable
    iCon = World.GetVariable ("varStatCon")
    iInt = World.GetVariable ("varStatInt")
    iWis = World.GetVariable ("varStatWis")
    
    'evaluate rolled stats
    if iCon >=  20 and iInt >= 20 and iWis >= 20 then
    World.Sound "sound.wav"
    exit sub
    else
    World.DoAfter 1, "n" 'Tell the mud these stats aren't wanted, reroll again.
    'After "n" is sent to the world, the mud again rolls stats, displays the
    'new stats, and, of course, the prompt line again.
    'So the trigger fires again, and continues to do so until the if condition is true.
    end if
    end sub


    Anything I'm doing wrong? The script/trigger always fires one extra command that ruins the effectiveness of the pair. Sorry if my code isn't the best.
Australia Forum Administrator #1
I'm a bit worried about the "DoAfter". I think it will send the "n" a second too late.

I would do a "Send" rather than DoAfter, because the DoAfter will introduce a timing problem.
Australia Forum Administrator #2
In other words, if the MUD re-rolls in half a second, the "n" arrives after one second, so that interval will give you the "n" you don't want.
USA #3
But shouldnt that not matter? since there would be a correlation between the "n"s and the prompts?
It just adds a lag time... Since the mud wouldnt have anything else sent until a y or n was recieved.
USA #4
Sadly, I had already considered using send instead of doafter, and it still does the same... and yes, I sorta figured that doafter wouldn't do much, since doafter would wait for the trigger to fire first. I just put it there so that it's not a constant stream of "n"s.
I sadly get the same result with world.send as I do with world.doafter. The trigger line is on a line by itself, so that shouldn't pose any problems... in fact, here's a paste from the mud's stat roller:
Strength : 11
Intelligence : 16
Wisdom : 14
Dexterity : 12
Constitution : 22

Do you wish keep these stats (y/n)?

I was thinking it may have something to do with the mud sometimes not sending out a linefeed, but I'm not altogether sure of that.
#5
Well... A few things. Try using cInt() on the variables. Perhaps they're being read as text strings instead of numbers? That would screw up your evaluations, since your looking for a numerical value.


if cInt(iCon) >=  20 and cInt(iInt) >= 20 and cInt(iWis) >= 20 then


Or, if that doesn't solve it:

In the ScriptStatCheck sub, add this right above the evaluation part. This will show you if its picking up the values correctly.


World.Note "Con: " & iCon & "Int: " & iInt & "Wis: " & iWis


Australia Forum Administrator #6
Quote:

I was thinking it may have something to do with the mud sometimes not sending out a linefeed, but I'm not altogether sure of that.


You are probably right about that, as it would effectively be reacting to the 2nd-last roll. This topic has been covered at some length before, and I think I did a stat roller plugin, or example, that showed how to detect a line without a linefeed - basically you use a timer that checks the last line in the buffer. This timer would also have the effect of slowing down replies to one a second.