Scripting an Activator with getvariable and IFs!

Posted by Lupin on Fri 26 Sep 2008 05:32 AM — 9 posts, 30,744 views.

#0
OK! first off what my goals is. Hit a button do the correct movements! Those movements are!

first off the Activator of choice would be CTRL+A for simplicity.

Now when CTRL+A is hit I want it to run a script.

This script needs to get two variables one being used in ifs

example.

cstance = GetVariable("cstance") -- stance
tar = GetVariable("tar"} -- Target

if cstance == nil then
Note (/DoCommand "change stance gyanis")
if cstance == "gyanis" or "Rizet"
Note (/DoCommand "Sitara lateral @tar/nsitara vertical @tar/Sitara lateral @tar")
if cstance == "ein-fasit"
Note (/DoCommand "Sitara vertical @tar/nSitara lateral @tar/nsitara vwerical @tar")
else
Note (/DoCommand "Stiara crescentcut @tar/nsitara lateral @tar/nsitara vertical @tar")
end

all the @tar instances is where the second variable would be inserted... if anyone could help me out with throwing it together I'd appreciated it
USA #1

cstance = GetVariable("cstance") -- stance
tar = GetVariable("tar") -- Target

if cstance == nil then
Send("change stance gyanis")
elseif cstance == "gyanis" or cstance == "Rizet" then
Send ("Sitara lateral " .. tar .."/nsitara vertical " .. tar .. "/Sitara lateral " .. tar)
elseif cstance == "ein-fasit" then
Send ("Sitara vertical " .. tar .. "/nSitara lateral " .. tar .. "/nsitara vwerical " .. tar)
else
Send ("Stiara crescentcut " .. tar .. "/nsitara lateral " .. tar .. "/nsitara vertical " .. tar)
end
Amended on Sun 28 Sep 2008 07:26 AM by WillFa
#2
Awesome! Knew i messed up in the actual coding since note just sends the text to the screen :/. How would I get the 'CTRL+A' to exectute the script?

script name is Test and the function above is Hit.

USA #3

<aliases>
  <alias
   script="Hit"
   match="KungFu"
   enabled="y"
   sequence="100"
  >
  </alias>
</aliases>


Copy the above, go to File, Import..., "From clipboard". (It makes an alias "KungFu" that runs the script function.)

Add to the script file, outside of a function:

Accelerator ("CTRL+A", "Test")

which makes the macro linking to the alias which links to the script function which is connected to the ankle bone...

Amended on Sat 27 Sep 2008 10:48 PM by WillFa
Australia Forum Administrator #4
Or, bypassing the need for an alias:


AcceleratorTo ("Ctrl+A", "Hit ()", sendto.script)


This binds Ctrl+A to "send to script" sending the function call Hit ().
#5
alright I tryed both approaches and the first approach didn't like the '<' a

the second approach gave me this

Run-time error
World: Impy
Immediate execution
[string "Script file"]:1: attempt to index global 'sendto' (a nil value)
stack traceback:
[string "Script file"]:1: in main chunk
Error context in script:
1*: AcceleratorTo ("Ctrl+A", "Hit ()", sendto.script)


well seeing as it said something was wrong with the main, something I didn't have I tossed it in empty and got

Compile error
World: Impy
Immediate execution
[string "Script file"]:21: '<eof>' expected near 'end'
Error context in script:
17 : Send ("stiara crescentcut " .. tar .. "/nsitara lateral " .. tar .. "/nsitara vertical " .. tar)
18 : end
19 : end
20 : main ()
21*: end

so i tossed in an <EOF> in the next line and it gave me the exact same compile error :/
USA #6
oops.

Add to the script file, outside of a function:

Accelerator ("CTRL+A", "KungFu")


The first part isn't pasted into the script file. It's just copied to the clipboard when you go to the file menu, and choose import...


(I have no idea why nick's solution didn't work. "Main Chunk" is what Mushclient calls code that's not in a function. <eof> stands for End Of File. It's saying that there's an extra end in there.)
Australia Forum Administrator #7
You must be using a version of MUSHclient earlier than 4.27.

That version introduced the built-in table of "sendto.xxx" so it would recognise sendto.script.


http://www.gammon.com.au/scripts/showrelnote.php?version=4.27&productid=0

Either upgrade versions, or change it to the equivalent, but less self-documenting:


AcceleratorTo ("Ctrl+A", "Hit ()", 12)


And take out that main () stuff, that was just a guess, right?

I noticed an error a while back, I hoped by now someone would have fixed it:


tar = GetVariable("tar"} -- Target


That is wrong, with the } there, it should be:


tar = GetVariable("tar") -- Target



Amended on Sun 28 Sep 2008 06:41 AM by Nick Gammon
#8
Thanks guys you are great!

finished code
function Hit(cstance, tar)
	cstance = GetVariable("cstance") -- stance
	tar = GetVariable("tar") -- Target
	if tar == nil then
		tar = "rat"
	end
	if cstance == "Vae-Sant" then
		Send ("sitara lateral " .. tar)
		Send ("sitara vertical " .. tar) 
		Send ("sitara lateral " .. tar)
	elseif cstance == "Ein-Fasit" then
		Send ("sitara vertical " .. tar) 
		Send ("sitara lateral " .. tar) 
		Send ("sitara verical " .. tar)
	elseif cstance == "Gyanis" then
		Send ("sitara lateral " .. tar)
		Send ("sitara lateral " .. tar)
		Send ("sitara vertical " .. tar)
	elseif cstance == "Rizet" then
		Send ("sitara vertical " .. tar)
		Send ("sitara vertical " .. tar) 
		Send ("sitara lateral " .. tar)
	else
		Send ("sitara crescentcut " .. tar)
		Send ("sitara lateral " .. tar)
		Send ("sitara vertical " .. tar)
	end
end

AcceleratorTo ("Ctrl+A", "Hit ()", sendto.script)