looking at your screenshots it looks like that “if bge.logic”… is at the top level (no indentation), and the variable “element” is declared inside the if-block, making it a local variable.
saveroutine() is a global function, and you try to read from “element”, which is not a local variable within the scope of that function, nor is a global variable.
Thanks!
Realising it`s about the priorities of the global and local state… I at least made it work.
Only using one local varible and increasing the function… containing everything necessary…