First, you need to add the main gui hook to the party definition like this:
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onDrawGui = function(g)
guiScript.doGui(g)
end,
}
Code: Select all
function doGui(g) -- triggers EVERY frame by render gui hook
--code
end
For this example, let's just do a simple print message when you press the 'm' key. Change your guiScript code to:
Code: Select all
mFree = true
function doGui(g) -- triggers EVERY frame by render gui hook
if g.keyDown("m") then
if mFree then
print("m key was pressed")
--other code
end
mFree = false
else -- key no longer being held down
mFree = true
end
end
You'll notice I added a "global" variable called mFree just before the function. This acts as a flag so that holding the key down won't trigger the code to be run multiple times in a row. The first frame rendered after you press the key checks to see if mFree is true, and only if it's true does it run the code, and it also sets it to false, preventing the code from running again until you first let go of the key (to set the flag true) to make it available again.
If you want to test some feature over and over, you can temporarily put in a link in this code, such as:
Code: Select all
mFree = true
function doGui(g) -- triggers EVERY frame by render gui hook
if g.keyDown("m") then
if mFree then
--print("m key was pressed")
myOtherScript.myOtherTestFunction()
end
mFree = false
else
mFree = true
end
end
You can use this for testing things out when designing complex puzzles, or you could add this as an actual gameplay feature for players to use in your dungeon, making 'm' be a new interface key which casts a free missile spell or something, whatever you want, anything is possible!