draw/sheathe weapon key

Post Reply
Jazzek
Posts: 2
Joined: Sun Sep 18, 2022 2:18 am

draw/sheathe weapon key

Post by Jazzek »

Hi, I'm trying to make a simple script on my keypad 0 to draw/sheathe my weapons.
I have the following:

sheathed = getVariable("WeaponSheathed")
echo("sheathed")
if sheathed == "yes" then
send("draw weapons from scabbard belt")
setVariable("WeaponSheathed", "no")
elseif sheathed == "no" then
send("sheathe sword")
send("sheathe knife")
setVariable("WeaponSheathed", "yes")
end

I put the echo in to see if it is getting the variable.
I have the variable WeaponSheathed set up, and set it to string type, and set it to yes

I was going to just use boolean, but couldn't work out how to use that. Haven't done mudlet scripting in a while.
Any help would be appreciated.

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: draw/sheathe weapon key

Post by demonnic »

Hi!

You don't need to setup variables in advance, or use get/setVariable like in MUSHclient. So you can set the variable in a trigger, without ever touching the Variables view in the script editor. And you can write the above like so:
Code: [show] | [select all] lua
if WeaponSheathed == "yes" then
  send("draw weapons from scabbard belt")
  WeaponSheathed = "no"
else
  sendAll("sheathe sword", "sheathe knife")
  WeaponSheathed = "yes"
end
I use else because the variable only has the two states. And sendAll is the preferred way to send multiple things in a row like that =)

Jazzek
Posts: 2
Joined: Sun Sep 18, 2022 2:18 am

Re: draw/sheathe weapon key

Post by Jazzek »

thank you :-)

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: draw/sheathe weapon key

Post by Jor'Mox »

Since you mentioned using booleans for the variables, I figured I'd drop in and show how to change demonnic's code to use them.
demonnic wrote:
Sun Sep 18, 2022 1:29 pm
Code: [show] | [select all] lua
if WeaponSheathed then
  send("draw weapons from scabbard belt")
  WeaponSheathed = false
else
  sendAll("sheathe sword", "sheathe knife")
  WeaponSheathed = true
end

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: draw/sheathe weapon key

Post by demonnic »

Oh... yeah, somehow I managed to gloss over that part of the original post. Thanks!

Post Reply