Hmm. The script works as is for me, assuming that you have pressure plate called knap_text_5... (though Komag is right, you don't need the 'key =' part).
Maybe you don't actually have the script connected to the pressure plate? You need to add a connector from the plate object to the script, and set the action to "l1spwnkey" Then your function will only run when the plate is activated, and the flag will stop the function from running twice. In this case, since the function is only every ever called when the plate is activated, you don't need to check isDown(), simplifying your script to:
Code: Select all
keySpawned = false
function l1rspwnkey()
if not keySpawned then
hudPrint("Oh look! There is a key on the floor.")
spawn("brass_key", self.level, 13, 16, 3, "FANCYBRASSKEY")
keySpawned = true
end
end
Furthermore, you can spawn the key at the location of the plate by referencing the optional parameter to your function. When the connector is triggered, the pressure plate is passed into the function, then you can pull the level, x, and y values from the location of the plate.
Code: Select all
keySpawned = false
function l1rspwnkey(plate)
if not keySpawned then
hudPrint("Oh look! There is a key on the floor.")
key = spawn("brass_key", plate.level, plate.x, plate.y, 3, "FANCYBRASSKEY")
keySpawned = true
end
end
This has the added advantage that you can move the pressure plate around (even across levels) and the key will still spawn!