Scripting Variables and Returning

Posted by Zeppy on Tue 13 Mar 2001 01:03 PM — 6 posts, 22,878 views.

USA #0
This is likely a very simple set up, but for some reason it eludes me at the moment. I have a very simple variable setup that I'd like to do.

Currently I have a trigger for when I am disarmed that simply reacts to a disarm prompt and sends commands to get weapon and wield weapon.

What I want to do is set the weapon to a variable and then return it from within the trigger.

So here is the essence of it:

world sends:
soandso disarms you!

trigger sends to world:
get $weapon
wield $weapon

So "$weapon" would be the variable in this case. I'd like to set the variable with an alias then returns that value within the above trigger. Simple enough I'm sure, but I'm having major cerebral flatulations in deciding how to code it.

Suggestions?
USA #1
OK. Now that I posted it, I think I got an answer on another thread. Let me see if this is about right...

alias: weapon
send: nothing
script: weapon_varset

script:

sub onaliasweapon_varset(varname, weapon)
world.setvariable curweapon, weapon
end sub

Then when I want to send that to the world I would have this:

trigger: soandso disarms YOU!
send: get @curweapon;wield @curweapon
expand variables: checked


Is that right or am I just kidding myself?
Australia Forum Administrator #2
You are very close. :)

I would make the script quote the weapon variable name, and also the alias needs three arguments (the third being a list of wildcards), like this:


sub onaliasweapon_varset (strAliasName, strOutput, arrWildCards)
world.setvariable "curweapon", arrWildCards (1)
end sub


The alias now needs to match on a wildcard (the weapon name), you need to specify a label before it will let you type in a script name, and the script name needs to match what you specified in the alias (onaliasweapon_varset), like this:


alias: weapon *
send: nothing
label: weapon_varset
script: onaliasweapon_varset


I would probably put the trigger response over multiple lines, but if it works, then leave it alone. Also, maybe use a wildcard so it works if anyone disarms you.


trigger: * disarms YOU! 
send:    get @curweapon
         wield @curweapon 
expand variables: checked 




Amended on Tue 13 Mar 2001 01:33 PM by Nick Gammon
USA #3
Let me make sure I have one element correct. The line "onalias" has no more function than anything else. So if I wanted to call the script "Sub weapons" it would be just the same as calling it "Sub onaliasweapon_var" right?

Sorry for the lame questions...I try do better. :-)
Australia Forum Administrator #4
I'm not absolutely sure I understand the question.

The alias calls a subroutine (sub) by name. The subroutine has to have the name you specify. The name doesn't matter, but it has to agree between what the alias specifies, and what the sub has.

You could call it "rocketship" if you want to, but you have to do that in two places, eg.

Alias


Match: test
Label: blahblah
Script: rocketship


Script


sub rocketship (strAliasName, strOutput, arrWildCards)
world.note "test alias script"
end sub


Amended on Wed 14 Mar 2001 12:53 PM by Nick Gammon
USA #5
OK cool. You answered the question fine. Sorry I wasn't more clear. Thanks a ton and keep up the great work! It's really a fantastic application!