Half second timers

Posted by David on Sun 15 Apr 2001 04:00 AM — 41 posts, 124,360 views.

USA #0
I know I was talking about this before in another forum, but I decided to move it here.

The problem:

The MUD is a timered based MUD, This means everything that is done can be reacted to.

Instead of rolling dice to see if you hit, its based on literal timing. If i punch You you have 1.5 seconds to reacts and parry, or dodge the attack.

I have worked out the trigger code, thanks to you Nick.(I would still be stumbling along otherwise)

You mentioned about making "one shot" timers, I think that is a great idea.

I would love to implement that, i read the other forums regarding addtimer, its far more complex than what i am needing.

first thing:
world.addtimer (??????) what goes here, I did not understand what was being said in the other forums.

Second thing:
I need a timer that A. waits 1.5 seconds before sending something to the world, Or B. the script which does all the thinking, meaning it waits X amount of time before sending to the world my command of "parry High". From what I read it doesn't sound like scripting can do that. I understand you can't Pause the script without stopping everything, someone mentioned something about a wait command. It was a little too complex for me to understand. Perhaps you might simplify what it meant for me.

Thanks for the help again.

Australia Forum Administrator #1
OK, first let's look at the difference between manually entering a timer or trigger, and doing it in a script.

By "manually" doing it, you simply use the MUSHclient configuration screen to type in a trigger, timer, alias or whatever. This is fine if you can plan to do something in advance, like set up a timer that says "inventory" every hour to stop your being disconnected for inactivity.

However you might want to have a script add a timer, for example if you want to do something 2 seconds after a trigger fires.

Addtimer (in a script) looks like this:


World.addtimer "my_timer", 1, 10, 30, "parry high", 5, "my_timer_script"


(This is in VBscript). Breaking it up piece-by-piece ...


"my_timer" - the name of the timer (used if you need to delete or reset it)
1 - the number of hours to wait, plus
10 - the number of minutes to wait, plus
30 - the number of seconds to wait
"parry high" - what to send to the MUD
5 - some flags - in this case enabled=1 plus one-shot=4. So, adding the flags together gives 5.
"my_timer_script" - the name of the script to execute when the timer fires (optional)


The various flags are documented on the page http://www.gammon.com.au/mushclient/functions.htm.

For example, if you add 2 to the flags it becomes a timer that fires at a particular time (in this case 01:10:30).

Now, to solve your problem, basically you want to set up a script that, when you are attacked, sends "parry high" 1.5 seconds later.

The first point is that I haven't allowed for sub-second timers. In my view, because of lag and other considerations, rounding to the nearest second should be good enough. So, let's make it 2 seconds.

You need, then, a trigger that matches on the event that needs the parry. You haven't said what that is, but let's assume it is something like:


The Gorgon attacks you!


Thus, you set up a trigger like this:


Trigger: * attacks you!
Label: attack_trigger
Script: OnAttack


Then you need a script routine (OnAttack) that sets up the timer to fire 2 seconds later and do the parry. Thus you add to the script file:


sub OnAttack (TriggerName, TriggerLine, Wildcards)
World.addtimer "my_timer", 0, 0, 2, "parry high", 5, ""
end sub


This trigger adds a one-shot timer that fires in 2 seconds. When it fires it sends "parry high" and then deletes itself.

This is simple enough. You can modify this general idea for all sorts of things.
Amended on Thu 19 Apr 2001 10:57 PM by Nick Gammon
USA #2
Ok, So basically There is no possible way to make a 1.5 second timer.

I was browsing the forums, and I came across something interesting.

I see:
* <insert name> Retracts his right arm...

Now I saw you make a post about regular expressions in a trigger, making asterisks asterisks not wildcards

My question is:

Can you make a regular expresion with a wildcard in it?

As a side thought:

Also, currently i am using the copy wildcard to clipboard in most of my aliases

E.g
* Apoc retracts his right arm...

My trigger is:

* * retracts his right arm...

I copy the second wildcard to the clipboard

My alias:

Match on: pr
sends to world: punch right %c

My original though was to use variables.

i wanted my trigger to set a variable as an attacker( I got the same problem as someone else did, it will work from the command box, but not as a trigger)

E.g.

* Apoc retracts his right arm...

I now know how to use a trigger in scripting, I do not know how to translate my wildcards from the client to the script

I want to beable to use scripting in my aliases instead
of %c

If I go and look at my variables I see:

Name: Attacker
Content: Apoc

The 2 things I need to know about this part is:
A. How do I copy my wildcard to my variable list?
Would it Look something like this?

sub Attacker (PunchRight, trig_line, arrWildCards)
world.setvariable "Attacker", arrWildCards (2)
End Sub

B. How do I then setup my aliases to use that information?

(If I recall correctly, thought I don't know how to do it, When you set a variable, and then reset a variable with different information as long as its the same name the old one will be replaced.)

I feel that scripting this over using the %c will be more effecient, and allws me to use that for other things

Australia Forum Administrator #3
Yes, you can make regular expressions match on wildcards. In fact, in this version of MUSHclient, internally all triggers are translated into the matching regular expression, so it uses a single regular-expression matching routine on incoming text. In your example:


* * retracts his right arm...


The regular expression you want (assuming that the first asterisk is a literal asterisk) is:


^\* (.*) retracts his right arm...$


The "^" says "match on start of line".
The "$" says "match on end of line".
The "\*" is a literal asterisk.
The "(.*)" is a match on one or more characters of any type.

The brackets also mean "save this in the wildcard array". In other words, this then becomes wildcard %1 in the trigger. (You used wildcard 2 because you had two lots of asterisks).

Quote:

Would it Look something like this?

sub Attacker (PunchRight, trig_line, arrWildCards)
world.setvariable "Attacker", arrWildCards (2)
End Sub


Yes, that is exactly right, although in the example I gave the (2) becomes a (1).

To use this variable in an alias, check "Expand variables", and then put an "@" in front of the variable name in the alias expansion, like this:

Send: kick @Attacker

I think variables are more powerful than the clipboard, which was really retained for historical reasons. If you keep using the clipboard, and then while all your aliases and triggers are working away, want to copy and paste something in the command area, you will find that halfway through, your clipboard has changed.

And yes, you are correct that setting a variable replaces the previous contents, if any.





Amended on Thu 19 Apr 2001 10:59 PM by Nick Gammon
USA #4
I tried putting that into my script. It did not do as advertised. Also, when I code that particular part:

sub OnAttacker (>>PunchRight<<, triggerline, arrWildCards)
world.setvariable "Attacker", arrWildCards (1)
End Sub

Does the name HAVE to be that? >>PunchRight<<

I need all the attackes to run this subroutine.

Will any name work?

I didn't get any error's It just didn't work
. What did i do Wrong?

Trigger looks like this:
Match on: ^\* (.) retracts his right arm...$
Send: Blank
CopyWildcard to clipboard none
Name: PunchRight
Script OnAttacker
USA #5
Oh yeah I got the script to work, but not the exact expression part of it.
USA #6
Ok, Question:

Can a script do time functions?

I.E, it waits a certain amount of timer before sending information to the MU*?

If so, how would i do that(if possible)?

Sencondly, If the script can "wait" a number of seconds, then can you therefore, by using divion function, create a half second, then have the script send that to the mud, hence starting a 1 second "one shot" timer, after the scrip has already waited .5 seconds internally?


This is the only way I can see possible to do sub-second timers.

Thanks David
USA #7
Ok Played with Regular expressions for 5 hours(I had been up for 20+ hours on 2 hours sleep do to work) I figured out how they work, your example you gave me for the trigger was 99% correct

^\* (.) retracts his right arm... $

The problem was the $tring sign was in the incorrect place.

I hate to have 50 milliong questions.

My next little project is what I call "AutoCombo"

Some times when you "parry" an attack, it will give you a combonation of attacks you may do:

Combination! ( lp rp s lp s )

lp=Left punch
rp=Right punch
s=sweep
r=RoundHouse
(note there is no r in this combo)

My question is How would you script this?

My first thought was once again to use variables
However, you do not always get 5 attacks in a combo
Sometimes you get 2
Combination! ( lp rp )
Combination! ( lp rp s )
Combination! ( lp rp s lp )
Combination! ( lp rp s lp s )
In any order possible of the 4 attacks
And on Occasion you will get a second combonation screen or 3rd or 4th, it all depends on how fast you are. and there is a percentage tossed in there as well

Then I realized that variables might not be the answer to this question, so there must be something I gotta do to do this.

Thank you.
USA #8
I was thinking about this Just after I saved my post, I could do something like this:


Triggers match on: ^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) )$

Now.. I got the trigger worked out. its a bit harsh on the eyes. but I think this will work as regular expression

Here is where I am get confused. I think I got a solid Idea here. But I don't know where to go with it from here.

Will you give me some suggestions, am I on the right track?
Or have I gone a completely different route than I should?
Australia Forum Administrator #9
Quote:

sub OnAttacker (>>PunchRight<<, triggerline, arrWildCards)
world.setvariable "Attacker", arrWildCards (1)
End Sub


No, the name is supplied to you, which is the label of the trigger. Just do this:


sub OnAttacker (Triggername, triggerline, arrWildCards) 
world.setvariable "Attacker", arrWildCards (1) 
End Sub 


Australia Forum Administrator #10
Quote:

Triggers match on: ^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) (lp|rp|s|r) )$
____________________________________________________________
^Combination! ( (lp|rp|s|r) (lp|rp|s|r) )$


You can do it a bit simpler than that. A regular expression can match on one or more of something, and that something can be "this" or "that".

So, I would do it like this:


Match on: ^Combination! \( (lp|rp|s|r)* \)$


This matches on one or more of: lp, rp, s or r

The "\(" matches a bracket, literally.
Amended on Mon 16 Apr 2001 11:14 AM by Nick Gammon
Australia Forum Administrator #11
Quote:

Can a script do time functions?

I.E, it waits a certain amount of timer before sending information to the MU*?


No, and I wouldn't get too worried about trying to time 0.5 seconds. Network lag, and normal human reaction time, are likely to eat into 1/2 second pretty well.
USA #12
Ok Well, the problem is there is going to have to be commands entered by the computer.

When The combonation comes up:
Combonation! ( lp lp rp s r ) <or whatever the string of attacks are at the time>

I want MUSHClient to do what the Combonation is for me.
I can do it fast enough typing, but i am too lazy while playing :)
Australia Forum Administrator #13
If you use the regular expression I suggested a few posts back, the string in question will be in the first wildcard. Then just write a script to "walk" the wildcard value (stopping at spaces) and send the appropriate command to the MUD.
USA #14
When you set a regular expression trigger, does the trigger start at the beginning of the liine?

For instance:

^\* (.*) retracts his (right|left) arm...$
Thats my trigger

Now what I want to know is will the trigger still fire if I see something like this on the screen"

<1234643/2355466pl> * Apoc retracts his right arm...

Does the ^ signify where the trigger starts looking for something? and the $ is when it stops.
Instead of looking at the entire line, it only searches for thet string of characters, regarless of whats infront or behing the trigger?


I know how to use addtimer, but what if i wanted to put a wildcard into it

world.addtimer "blah", 0, 0, 2, "(need to punt wildcard here)", 5, ""

Same goes for an alias I need to make

Alias:
^(.*)= (.*) (.*)$


Punch right=rp @attacker

I got the Alias part Ok
When I do a world.addalias though. I don't know how to put wildcards into it.

world.AddAlias name, match_text, response_text, parameter, flags, scriptname

world.addalias "(wildcard)", "(wildcard)", "(not sure what parametr is)", eEnabled, ""

I am thinking now that to put wildcards i will have to do something like this:

sub OnAliasCreation (CreateAlias, Triggerline, arrWildCards)
world.addalias arrwildcard (2), arrWildCard (2), arrWildCard (1) arrWildCard (3), "", eEnabled, ""
end sub

Is this correct?
If not, please how do I put wildcards into aliases?


Australia Forum Administrator #15
Regular expressions

The examples I gave used:


^ - start of line
$ - end of line


Just leave them out if that is not what you want.

eg.


^Nick$ - "Nick" alone on the line

^Nick - "Nick" at the start of the lione

Nick$ - "Nick" at the end of the line

Nick - "Nick" anywhere on the line


Wildcards in timers

Quote:

I know how to use addtimer, but what if i wanted to put a wildcard into it

world.addtimer "blah", 0, 0, 2, "(need to punt wildcard here)", 5, ""



I'm not sure what you mean here. A timer goes off after so many seconds, you don't put a wildcard in it. However if you mean the wildcard from the trigger, here is an example. Say you have a trigger that matches on a monster name, eg.


* attacks you!


Then in this case the monster name is wildcard #1. So, to make a timer that says "kick dragon" after 2 seconds (assuming that the monster is a dragon) you would do this:


sub OnAttack (TriggerName, TriggerLine, Wildcards)
World.addtimer "my_timer", 0, 0, 2, "kick " + Wildcards (1), 5, ""
end sub


By using "+" you concatenate together two strings, in this case "kick" and the contents of wildcard 1.

Wildcards in aliases

Quote:

Same goes for an alias I need to make

Alias:
^(.*)= (.*) (.*)$

Punch right=rp @attacker


You would do a similar thing there ...


sub OnAliasCreation (TriggerName, Triggerline, arrWildCards)
world.AddAlias ("alias_" + cstr (world.getuniquenumber), arrWildCards (1), arrWildCards (2) + arrWildCards (3), 1 + 1024, "");
end sub


What the above is doing is:


Alias name: alias_22 (just a unique name for it)
Match on: Wildcard 1
Send: Wildcard 2 + Wildcard 3
Flags: Enabled + Replace any existing one of the same name
Script: None


USA #16
I need to know the flag for extended variables

Or where i can find it


USA #17
Ok NM on the flag, I found it after a little searching



You mentioned several posts back about a script that "walks" a trigger.

Pardon me for my cluelessness, but I don't even have a clue where to start something like that.

If you could, Please give me some Idea of what i would need to do to make a "walking " script
Australia Forum Administrator #18
Hmm - after a bit of research I found the "split" function, which is just what you need. :)

I quote from the VBscript manual, which shows the general idea ...

Split

Description

Returns a zero-based, one-dimensional array containing a specified number of substrings.

Syntax

Split(expression[, delimiter[, count[, compare]]])

The Split function syntax has these parts:

expression

Required. String expression containing substrings and delimiters. If expression is a zero-length string, Split returns an empty array, that is, an array with no elements and no data.

delimiter

Optional. String character used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.

count

Optional. Number of substrings to be returned; -1 indicates that all substrings are returned.

compare

Optional. Numeric value indicating the kind of comparison to use when evaluating substrings, as follows:

0 Perform a binary comparison.
1 Perform a textual comparison.

Remarks

The following example uses the Split function to return an array from a string. The function performs a textual comparison of the delimiter, and returns all of the substrings.



Dim MyString, MyArray, Msg
MyString = "VBScriptXisXfun!"
MyArray = Split(MyString, "x", -1, 1)
' MyArray(0) contains "VBScript".
' MyArray(1) contains "is".
' MyArray(2) contains "fun!".





In your case you want to use "split" on a space delimiter (which is the default anyway), so (without testing it) I would guess you would want something like this:


Dim MyArray

MyArray = Split (wildcards (1))


Now you can "walk" (there's that word again!) each of the elements in the array, as in this example:


Dim i
for i = lbound (MyArray ) to ubound (MyArray )
world.note MyArray (i)
next



USA #19
So lets see if I am as smart as I think I am.

I have this for a trigger match:

Combonation! ( rp s lp s r )


Match on: ^Combonation \( (rp|lp|s|r) * \)^
send to world: Blank
flags:enabled, and regular expression clicked on, all else off
Name:AutoCombo(for lack of a Better name)
script: OnAutoCombo

Now for the doozy:

sub OnAutoCombo (TriggerName, Triggerline, arrWildCards)
Dim AutoCombo
Autocombo= split (arrWildCards (1))
Dim i
for i=lbound (AutoCombo ) to ubound (AutoCombo )
world.send AutoCombo (i)
next
end sub

Ok Now about the trigger

^Combonation \( (rp|lp|s|r) * \)^
Is the (rp|lp|s|r) a wildcard?

I don't think it is
so what i think I can do is this

^Combonation \( (.*) \)^

That should work.
I am off to try to imp this, Get back to you soon with sucess, I hope.
USA #20
Ok, here is my results

First I could not get the regular expression trigger to work
Maybe i did something wrong, i am sure after playing with it i will get it to work

Now. I change the trigger to:
Combination! ( * )

And did the aforementioned code

It worked almost perfectly:

When i did:
world.note AutoCombo (i)
next
end sub

It worked perfectly

However, when I did:
world.send AutoCombo (i)
next
end sub

It did not work
I got the typical huh? type ? or help commands for help

I how would I change it so that i made it walk the combo using variables?

rp=punch right @attacker

sending rp at the command box works fine, sending rp from the script doesn't

what do I have to do to make it think rp=punch right @attacker

Just so you know that Split works perfectly
Australia Forum Administrator #21
I would do something like this:


'
' loop through each possible response
'
Dim i, attack 
for i=lbound (AutoCombo ) to ubound (AutoCombo ) 
  Select Case AutoCombo (i) 
    case "rp" attack = "punch right"
    case "lp" attack = "punch left"
   ' ----> and so on for each different one
    case "s" attack = "blah"
    case "r" attack = "blah
    case else attack = ""  ' unknown attack type
  End Select          

' send our response if we found one
  if attack <> "" then
     world.send attack + " " + world.GetVariable ("attacker")
  end if
next 
USA #22
sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if attack <> "" then
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub

Wasn't 100% sure how to add the code you gave me.
I guessed in the implementaion,

I got an error:
-2146828275
Execution of line 77 column 1
AutoCombo split (arrWildCards (1))<--- Line 77
Type mismatch: 'AutoCombo'

Function/Sub: OnAutoCombo called by trigger
Reason: processing trigger "AutoCombo"

Unable to invoke script subroutine 'OnAutoCombo' While Processing trigger 'AutoCombo'
USA #23
Of course, 5 minutes after I post something, I figure out what i did wrong, I re looked at the code,

I re-read all the posts regarding it, and I noticed, i am missing an = sight

It shouls be:
AutoCombo = split (arrwildcards (1))

It was:
AutoCombo Split (arrWildCards (1))


I fixed it, and put everything the way I thought it should be...

It worked like a charm

Thanks Nick
USA #24
Ok, new problem

Autocombo works great

I want to add a twist to it now

Match on:Combination! ( rp rp r s r )

Now I end up getting the 5 attacks based on the select case part

What I want to do is end the combo, and insert another command instead of the last attack

In this case:

punch right
punch right
roundhouse
sweep
----- End string of characters ----
insert, Throw <Variable> down, instead of roundhouse

Someone mentioned using a counting function

if rp rp r s r=5 arrays
then select case for 4
and after next:

end if
next
world.send "throw " + world.getvariable ("attacker") + " down"
end sub
Australia Forum Administrator #25
That sounds about right.

You know the number in the array, so your test would be something like:


if i = ubound (AutoCombo ) then
  world.send "throw " + world.getvariable ("attacker") + " down" 
else
  world.send attack + " " + world.GetVariable ("attacker")
end if

USA #26

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo ) 
  Select Case AutoCombo (i) 
    case "rp" attack = "punch right"
    case "lp" attack = "punch left"
    case "s" attack = "sweep"
    case "r" attack = "roundhouse"
    case else attack = ""  ' unknown attack type
  End Select          
  if i = ubound (AutoCombo ) then
    world.send "throw " + world.getvariable ("attacker") + " down" 
  else
    world.send attack + " " + world.GetVariable ("attacker")
  end if
next
end sub



Does this look right to you?
Australia Forum Administrator #27
You took out my suggested test for a blank attack (in an earlier post) but yes, that looks about right.

Doesn't it work?
USA #28
Sorry, Yes it works beautifully. However I need to do something else now...


There are mob names that are more than one string of characters.

For instance, if i am fighting a playe(only one word names)
I.E. Bob, Blastoid, etc...

However, Some mobs have multi-names

King Cold, Frieza's Henchman, Android 17, Android 18, etc...

The throw command has a variable in it.

throw <target> down, or Throw <target> West

This code:

world.send "throw " + world.GetVeriable ("Attacker") + " Down"

Works perfect for characters or mobs that have a single name. I.E. Saibaman, Or any PC name.

It does not work on multi-named mobs.

My question is, Using the split command how wuld I use it to set variables using the second array

sub UnNamed (TriggerName, Triggerline, arrWildCards)
Dim UnNamed
UnNamed= split (arrWildCards (1))
Dim i
for i=lbound (UnNamed ) to ubound (UnNamed )
world.SetVariable "UnNamed" + UnNamed (i)
next
end sub

I think this how I might do it.
This will give me the result I think I want, but it will be kinda sloppy in My opinion.
reason being, it will be continuesly setting multiple variables, potentially hogging CPU speed(although it will prolly be next to nothing)

I would like to tighten it up. so that it will only set the ubound (UnNamed ) as the variable, and ignores the ibound (UnNamed )

I thought about uusing the if, command

if i= ubound (UnNamed ) then
world.setvariable "UnNamed" + UnNamed (i)
end if
next
end sub

I don't think thats right, could you please correct me if I am wrong

Thanks again
Dave
Australia Forum Administrator #29
This seems strangely complicated to me.

First, what do you type into the MUD when you see a two-named monster?

throw Android 17 down?
throw 'Android 17' down?
throw "Android 17" down?

Knowing this will help answer the question.

Also, looking back through the messages in this section it isn't obvious how the monster name gets into the variable in the first place. How do you put it there? Through an alias?


USA #30
Hrm... I tried using the "" or the '' but this is a completely custom mud, it is not based on ANY MUD that I know of. it did not work

Its not ROM its not SMAUG, its not CIRCLE, its coded from scratch

I don't think there is the "" '' in it.

I got the code to do what i want, It splits the names into array's and uses the last one as the variable

What I want to do is make it a little tighter, instead of setting a varible for the first name "King", then "walking" to the next Array "Cold" and setting that variable as well.

I would prefere it to ignore all but the last array

and use that as the variable.

The split works, I just want to make it less cpu intensive... setting one varible instead of cycling through the names in the array's and setting multiple variables
Australia Forum Administrator #31
I'm not sure why you need to go to this trouble. If the variable contains "Android 17" and you want to send:


throw Android 17 down


... then it will work without further modification. It isn't clear if the problem is getting "Android 17" into a single variable, or what.
USA #32
Throw Android 17 down
That doesn't work

Throw "android 17" down
That doesn't work

It has to be a single word

throw android down
throw 17 down

This is what I am currently using to change my varible "attacker" to something that works

sub OnAttacker (Triggername, triggerline, arrWildCards)
Dim Sense
Sense = split (arrWildCards (1))
Dim i
for i=lbound (Sense ) to ubound (sense )
world.SetVariable "Attacker", sense (i)
next
End Sub

What I want to do is change this into seomthing like what we did with throw as the last command in the combo


Instead of setting 2 variables
the first being Android
and the second Being 17

I want it to ignore android and go straight to 17

Australia Forum Administrator #33
Ah, I see what you are doing now. :)

It is simpler than what you are doing. You don't need a loop just to get the last word in the list. Do this:


sub OnAttacker (Triggername, triggerline, arrWildCards) 
Dim Sense 
 Sense = split (arrWildCards (1)) 
 world.SetVariable "Attacker", sense (ubound (sense)) 
End Sub 



The split will give you one or more words.

"Ubound (sense)" gives you the offset of the last word.

"sense (ubound (sense))" gives you the last word itself.





USA #34
I knew there was a more simple way to do it...

Thanks.

A small side question however

Lets say I got a random set of charcter strings

rth slgjbgr gohu onaeog setgofnr

Ok random set of character strings..

I got the lbound, and the ubound part fine

What if i wanted to access something in the middle?
Is that possible to do?

How would you do so?

Also. another side thought.
I have this Trigger. I want it to run a script... Lets jsut say Autocombo for instance. However once it runs through the combo i get another Combination! ( * ) trigger, but the second Combination! ( * ) that I get, I want the script to act differently.

Is there a way to make the script create a new trigger, and timer to re-enable the old trigger, then run a different subroutine, from within the scrpt, to do something else, then go back to the original script?
____________________________________________________________
Ok this is a better way to put it I think. Its a map of what this thing is suposed to do
____________________________________________________________
Ok the first trigger is activated it-> runs a script to make a new trigger, and timer->Runs a "sub subroutine"(I.E. AutoCombo)-> The second Trigger comes-> Runs a differnet subroutine(IE autocombo)-> third trigger comes, Runs the same as the second-> the timer expires and changes the 2nd, and 3rd trigger, back to the first trigger, and completes the rest of the first script.

This is kinda confusing I am sure, but I think if you look at it, it does make sense in a wierd way
Australia Forum Administrator #35
Quote:

I got the lbound, and the ubound part fine

What if i wanted to access something in the middle?
Is that possible to do?


Well, if ubound is 6 then the middle would be 3.

eg.


blah = split ("rth slgjbgr gohu onaeog setgofnr")
world.note blah (ubound (blah) / 2)


This would show the word half-way through that list of words.
Australia Forum Administrator #36
Quote:

Ok the first trigger is activated it-> runs a script to make a new trigger, and timer->Runs a "sub subroutine"(I.E. AutoCombo)-> The second Trigger comes-> Runs a differnet subroutine(IE autocombo)-> third trigger comes, Runs the same as the second


You confuse me a bit by talking about two subroutines both called Autocombo (as VB is not case-sensitive) however, you can probably achieve what you are doing by having a flag which you test in the trigger.

Something like this:


sub OnTrigger (Triggername, triggerline, arrWildCards) 
dim flag

flag = world.getvariable ("flag")

if flag = "b" then
'  ..... do something here (action B) .....
else
'  ..... do something different here (action A) .....
  world.setvariable "flag", "b"
  world.AddTimer ("blahblah", 0, 0, 5, "", 1029, "On_Fix_Trigger");
end if
end sub

sub On_Fix_Trigger (strTimerName)
  world.setvariable "flag", "a"  
end sub



What you have here is a single trigger that does action A or action B depending on the flag. Initially the flag will be "a" (or empty) so action A is done. In this case we set the flag to "b" so the action B is done next time around, and set up a 5-second timer to change the flag back at the end of the 5 seconds.

The other sub is called by the timer to switch the flag back.




Amended on Fri 11 May 2001 02:15 AM by Nick Gammon
USA #37
Okies.

When your creating a new character, I want to set a varible for the race that you select

Let me show you the code that I am trying to do, maybe you will know what I am doing wrong

sub OnRace (Triggername, triggerline, arrWildCards)
world.setvariable "Race", arrWildCards (1)

dim flag

flag = world.getvariable ("Race")

if flag = "saiyan|human|namek|android" then
world.setvariable "Race", arrWildCards (1)
world.send arrWildCards (1)
else
world.note "That is an invalid Race selection, Please check spelling and capitalization (hint, Don't capitilize your race)"
end if
end sub

I guess the question is I need the race to be case sensitive The only way I can see how to do this is at character creation

How do I create an "or" statement in the script.

if flag = "any of these possibilities" then
do this
else
world.note "Try again type this"
end if

USA #38
Ok, again, I wasted time with posting, I ended up using elseif statement



It works, but I can not seem to get an alias added from within the script

This is what I am doing, it is giving me an errorsub OnRace (Triggername, triggerline, arrWildCards)
world.SetVariable "Race", arrWildCards (1)
dim flag
flag = world.getvariable ("Race")
if flag = "saiyan" then
world.setvariable "Race", arrWildCards (1)
world.send arrWildCards (1)
world.note "Your have selected: " + world.getvariable ("Race")
world.deletealias "RaceSelection"
world.setVariable "Kaioken", "off"
World.addalias "Kaioken", "kk", "", "", 1+32, "OnKaioken"
elseif flag= "human" then
elseif flag= "namek" then
elseif flag= "android" then
else
world.note "That is an invalid Race selection, Please check spelling and capitalization (hint, Don't capitilize your race)"
end if
end sub

Anyways,
This part isn't working, Why?

World.addalias "Kaioken", "kk", "", "", 1+32, "OnKaioken"


Australia Forum Administrator #39
The prototype for AddAlias is:

long AddAlias(BSTR AliasName, BSTR MatchText, BSTR ResponseText, long Flags, BSTR ScriptName);

You have specified:

World.addalias "Kaioken", "kk", "", "", 1+32, "OnKaioken"

You have supplied 6 arguments whereas AddAlias takes 5. That is your problem.




Australia Forum Administrator #40
Quote:

I need a timer that A. waits 1.5 seconds before sending something to the world ...


Version 3.61 onwards now implements sub-second timers.