Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are 
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the 
password reset link.
Due to spam on this forum, all posts now need moderator approval.
 
 Entire forum
➜ MUSHclient
➜ Lua
➜ Scripting an Activator with getvariable and IFs!
| Scripting an Activator with getvariable and IFs! | 
It is now over 60 days since the last post. This thread is closed.  
  Refresh page
  
    | Posted by | Lupin
  (4 posts)  Bio | 
  
    | Date | Fri 26 Sep 2008 05:32 AM (UTC) | 
  
    | Message | | 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
 |  | Top | 
 | 
  
    | Posted by | WillFa
  USA  (525 posts)  Bio | 
  
    | Date | Reply #1 on Fri 26 Sep 2008 06:40 AM (UTC) Amended on Sun 28 Sep 2008 07:26 AM (UTC) by WillFa
 | 
  
    | Message | | 
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
 |  | Top | 
 | 
  
    | Posted by | Lupin
  (4 posts)  Bio | 
  
    | Date | Reply #2 on Sat 27 Sep 2008 10:28 PM (UTC) | 
  
    | Message | | 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.
 
 
 |  | Top | 
 | 
  
    | Posted by | WillFa
  USA  (525 posts)  Bio | 
  
    | Date | Reply #3 on Sat 27 Sep 2008 10:45 PM (UTC) Amended on Sat 27 Sep 2008 10:48 PM (UTC) by WillFa
 | 
  
    | Message | | 
<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...
 
 
 |  | Top | 
 | 
  
    | Posted by | Nick Gammon
  Australia  (23,165 posts)  Bio
  Forum Administrator | 
  
    | Date | Reply #4 on Sat 27 Sep 2008 11:20 PM (UTC) | 
  
    | Message | | 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 ().
 |  | - Nick Gammon
 
 www.gammon.com.au, www.mushclient.com
 |  | Top | 
 | 
  
    | Posted by | Lupin
  (4 posts)  Bio | 
  
    | Date | Reply #5 on Sun 28 Sep 2008 02:57 AM (UTC) | 
  
    | Message | | 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 :/
 
 |  | Top | 
 | 
  
    | Posted by | WillFa
  USA  (525 posts)  Bio | 
  
    | Date | Reply #6 on Sun 28 Sep 2008 05:34 AM (UTC) | 
  
    | Message | | 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.)
 |  | Top | 
 | 
  
    | Posted by | Nick Gammon
  Australia  (23,165 posts)  Bio
  Forum Administrator | 
  
    | Date | Reply #7 on Sun 28 Sep 2008 06:40 AM (UTC) Amended on Sun 28 Sep 2008 06:41 AM (UTC) by Nick Gammon
 | 
  
    | Message | | 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
 
 
 |  | - Nick Gammon
 
 www.gammon.com.au, www.mushclient.com
 |  | Top | 
 | 
  
    | Posted by | Lupin
  (4 posts)  Bio | 
  
    | Date | Reply #8 on Sun 28 Sep 2008 08:04 PM (UTC) Amended on Sun 28 Sep 2008 08:47 PM (UTC) by Lupin
 | 
  
    | Message | | 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)
 |  | Top | 
 | 
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
26,011 views.
It is now over 60 days since the last post. This thread is closed.  
  Refresh page
![[Go to top]](/images/gototop.gif) top
 top