Page 1 of 1

draw/sheathe weapon key

Posted: Sun Sep 18, 2022 2:27 am
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.

Re: draw/sheathe weapon key

Posted: Sun Sep 18, 2022 1:29 pm
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 =)

Re: draw/sheathe weapon key

Posted: Mon Sep 19, 2022 6:58 am
by Jazzek
thank you :-)

Re: draw/sheathe weapon key

Posted: Mon Sep 19, 2022 10:00 pm
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

Re: draw/sheathe weapon key

Posted: Mon Sep 19, 2022 11:26 pm
by demonnic
Oh... yeah, somehow I managed to gloss over that part of the original post. Thanks!