[Closed] Script running twice when added to a keyboard shortcut
HI so I have recently written a script that works great in quads, but when I run it as a keyboard shortcut it runs the script twice. I am thinking it is cause I have an
on isEnabled return
(
what to check for
)
On execute do
(
script
)
Does it run the script once on a keyboard press, then the execute causes it to run again? How would I go about making it so the quad is grey and the keystroke is disabled if the isEnabled is false?
Thanks
Wouldn’t that be a simple if statement with a flag to ascertain the isEnabled function?
On execute do
(
if myFunctionIsEnabled then
(
script
)
)
Thanks for the replies
Erilaz – I tried that. Works the first time, but then won’t work when I hit the keyboard hotkey again. It really could be user error I am guessing.
Light – This is what I have it checking in the Isenabled. The script is quite straight forward. It just seems to run twice when bound to a keyboard for some reason. As I said before I am just trying to find the proper way to write this for future reference. Thanks I appreciate your time
Here is the whole script. I am just making a hotkey to go up the stack. I am sure it has been done a bunch before. Just a learning exercise.
macroScript UpModStack category:"Modifier Stack"
(
on isEnabled return
(
selection.count == 1 and $.modifiers.count != 0
)
on execute do
(
currentmodifier = undefined
totalmodifiers = $.modifiers.count
modifiername = modPanel.getCurrentObject()
basemodifier = $.baseobject
if modifiername != basemodifier then
(
currentModifier = modPanel.getModifierIndex $ modifiername
if currentModifier > 1 then
(
newModifier = (CurrentModifier - 1)
modPanel.setCurrentObject $.modifiers[newModifier]
)
)
else
(
modPanel.setCurrentObject $.modifiers[totalmodifiers]
)
)
)
I have tried your code, and it works OK as a hotkey.
I have written this. Can you please try that and tell me if it works OK as a hotkey:
macroScript UpModStack category:“Modifier Stack”
(
on isEnabled return (selection.count == 1 and selection[1].modifiers.count != 0)
on execute do
(
local sel = selection[1]
if modPanel.getCurrentObject() != sel.baseObject then
(
local mod = modPanel.getModifierIndex sel (modPanel.getCurrentObject())
if mod != 1 do modPanel.setCurrentObject sel.modifiers[mod – 1]
)
else modPanel.setCurrentObject sel.modifiers[sel.modifiers.count]
)
)
Light
Thanks for your time Light
I tried yours and had the same issue. I then changed the hotkey from the up arrow, which is what I was using before to a different key and now it works perfectly. It appears the be an up arrow issue for some reason on my end. I appreciate your time and I will be looking at your code more closely to see what you did better than mine. Thanks