Here's an example. Best to save your stack before testing!
on mouseUp
local tScript, tLine
put the script of card "MyCard" into tScript
put lineOffset("end opencard", tScript) into tLine
if tLine > 0 then
put format("put \"test\" into TestV") & LF before line tLine of tScript
set the script of card "MyCard" to tScript
end if
end mouseUp